product-select.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="product-select">
  3. <el-form :inline="true" :model="formData" class="demo-form-inline">
  4. <el-form-item label="">
  5. <el-input v-model="formData.keyword" maxlength="20" placeholder="店铺名称/商品ID/商品分组"></el-input>
  6. </el-form-item>
  7. <!-- <el-form-item label="上架状态">-->
  8. <!-- <el-select v-model="formData.status" placeholder="请选择">-->
  9. <!-- <el-option label="全部" value=""></el-option>-->
  10. <!-- <el-option label="上架" value="1"></el-option>-->
  11. <!-- <el-option label="下架" value="0"></el-option>-->
  12. <!-- </el-select>-->
  13. <!-- </el-form-item>-->
  14. <el-form-item label="官方分类">
  15. <el-cascader
  16. ref="cascader"
  17. v-model="formData.categoryId"
  18. :options="categoryList"
  19. :props="{ checkStrictly: true,label: 'categoryName',value: 'id',children: 'childs' }"
  20. clearable></el-cascader>
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button type="primary" @click="onSubmit">查询</el-button>
  24. </el-form-item>
  25. </el-form>
  26. <el-table
  27. ref="multipleTable"
  28. :data="tableData"
  29. max-height="500"
  30. border
  31. row-key="productId"
  32. @selection-change="handleSelectionChange"
  33. style="width: 100%">
  34. <el-table-column
  35. v-if="isMultiple"
  36. width="40"
  37. type="selection"
  38. :reserve-selection="true"
  39. fixed="left"
  40. >
  41. </el-table-column>
  42. <el-table-column label="" width="40" align="center" v-else>
  43. <template slot-scope="scope">
  44. <el-radio v-model="tableRadio" :label="scope.row"><i></i></el-radio>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="产品主图" width="180" align="center">
  48. <template slot-scope="scope">
  49. <el-image
  50. style="width: 80px; height: 80px"
  51. :src="scope.row.image"
  52. fit="contain"></el-image>
  53. </template>
  54. </el-table-column>
  55. <el-table-column
  56. prop="productName"
  57. label="产品名称"
  58. width="180">
  59. </el-table-column>
  60. <el-table-column
  61. prop="productId"
  62. label="产品ID">
  63. </el-table-column>
  64. <el-table-column
  65. prop="price"
  66. label="售价">
  67. </el-table-column>
  68. <el-table-column
  69. prop="originalPrice"
  70. label="原价">
  71. </el-table-column>
  72. <el-table-column
  73. prop="stockNumber"
  74. label="库存">
  75. </el-table-column>
  76. <el-table-column
  77. prop="number"
  78. label="销量">
  79. </el-table-column>
  80. </el-table>
  81. <el-pagination
  82. @size-change="handleSizeChange"
  83. @current-change="handleCurrentChange"
  84. :current-page="currentPage"
  85. :hide-on-single-page="true"
  86. :page-sizes="[10, 20, 50, 100]"
  87. :page-size="pageSize"
  88. layout="total, sizes, prev, pager, next, jumper"
  89. :total="total">
  90. </el-pagination>
  91. </div>
  92. </template>
  93. <script>
  94. import api from '@@/components/canvasShow/config/api'
  95. import {sendReqMixin} from '@@/components/canvasShow/config/mixin'
  96. import {checkEmptyChild} from '@@/config/common'
  97. import Cookies from 'js-cookie'
  98. import { mapGetters } from 'vuex'
  99. export default {
  100. name: 'product-select',
  101. mixins: [sendReqMixin],
  102. data () {
  103. return {
  104. tableRadio: '',
  105. formData: {
  106. keyword: '',
  107. status: '',
  108. categoryId: ''
  109. },
  110. currentPage: 1,
  111. total: 0,
  112. pageSize: 10,
  113. categoryList: [],
  114. tableData: [],
  115. multipleSelection: []
  116. }
  117. },
  118. props: {
  119. selectedRows: {
  120. type: Array,
  121. default: () => []
  122. },
  123. isMultiple: {
  124. type: Boolean,
  125. default: false
  126. }
  127. },
  128. mounted () {
  129. this.getCategory()
  130. this.getTableData()
  131. },
  132. computed: {
  133. ...mapGetters([
  134. 'typeId'
  135. ])
  136. },
  137. methods: {
  138. // 获取类别
  139. getCategory () {
  140. var _this = this
  141. let params = {
  142. url: api.getClassify,
  143. method: 'GET'
  144. }
  145. this.sendReq(params, (res) => {
  146. _this.categoryList = res.data
  147. checkEmptyChild(_this.categoryList)
  148. })
  149. },
  150. // 获取产品信息
  151. getTableData () {
  152. var _this = this
  153. var paramsUrl = `${api.getProducts}?page=${this.currentPage}&pageSize=${this.pageSize}&shelveState=1`
  154. if (this.formData.keyword) {
  155. paramsUrl += `&search=${this.formData.keyword}`
  156. }
  157. let shopId = parseInt(Cookies.get('shopID'))
  158. if (shopId && this.typeId===3) {
  159. paramsUrl += `&shopId=${shopId}`
  160. }
  161. let nodesObj = this.$refs['cascader'].getCheckedNodes()
  162. if (nodesObj && nodesObj.length !== 0) {
  163. var categoryId = nodesObj[0].value
  164. paramsUrl += `&classifyId=${categoryId}`
  165. }
  166. let params = {
  167. url: paramsUrl,
  168. method: 'GET'
  169. }
  170. this.sendReq(params, (res) => {
  171. _this.tableData = res.data.list
  172. _this.total = res.data.total
  173. // 表格斌值
  174. // if(_this.selectedRows.length > 0){
  175. // _this.selectedRows.forEach(row => {
  176. // this.$refs.multipleTable.toggleRowSelection(row,true);
  177. // });
  178. // }
  179. })
  180. },
  181. // 搜索
  182. onSubmit () {
  183. this.getTableData()
  184. },
  185. // 每页条数改变
  186. handleSizeChange (val) {
  187. this.pageSize = val
  188. this.getTableData()
  189. },
  190. // 当前页改变
  191. handleCurrentChange (val) {
  192. this.currentPage = val
  193. this.getTableData()
  194. },
  195. // 多选改变
  196. handleSelectionChange(val) {
  197. this.multipleSelection = val
  198. }
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .product-select{
  204. .el-pagination{
  205. padding: 0px;
  206. margin-top: 30px;
  207. }
  208. .el-table{
  209. .img{
  210. width: 80px;
  211. height: 80px;
  212. }
  213. }
  214. }
  215. </style>