多租户商城-商户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
6.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  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="$t('common.choose')">-->
  9. <!-- <el-option :label="$t('common.all')" 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">{{ $t('common.query') }}</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. import {getShopId} from "@@/utils/auth.js"
  100. export default {
  101. name: 'product-select',
  102. mixins: [sendReqMixin],
  103. data () {
  104. return {
  105. tableRadio: '',
  106. formData: {
  107. keyword: '',
  108. status: '',
  109. categoryId: ''
  110. },
  111. currentPage: 1,
  112. total: 0,
  113. pageSize: 10,
  114. categoryList: [],
  115. tableData: [],
  116. multipleSelection: []
  117. }
  118. },
  119. props: {
  120. selectedRows: {
  121. type: Array,
  122. default: () => []
  123. },
  124. isMultiple: {
  125. type: Boolean,
  126. default: false
  127. }
  128. },
  129. mounted () {
  130. this.getCategory()
  131. this.getTableData()
  132. },
  133. computed: {
  134. ...mapGetters([
  135. 'typeId'
  136. ])
  137. },
  138. methods: {
  139. // 获取类别
  140. getCategory () {
  141. var _this = this
  142. let params = {
  143. url: api.getClassify,
  144. method: 'GET'
  145. }
  146. this.sendReq(params, (res) => {
  147. _this.categoryList = res.data
  148. checkEmptyChild(_this.categoryList)
  149. })
  150. },
  151. // 获取产品信息
  152. getTableData () {
  153. var _this = this
  154. var paramsUrl = `${api.getProducts}?page=${this.currentPage}&pageSize=${this.pageSize}&shelveState=1`
  155. if (this.formData.keyword) {
  156. paramsUrl += `&search=${this.formData.keyword}`
  157. }
  158. let shopId = parseInt(getShopId())
  159. if (shopId && this.typeId===3) {
  160. paramsUrl += `&shopId=${shopId}`
  161. }
  162. let nodesObj = this.$refs['cascader'].getCheckedNodes()
  163. if (nodesObj && nodesObj.length !== 0) {
  164. var categoryId = nodesObj[0].value
  165. paramsUrl += `&classifyId=${categoryId}`
  166. }
  167. let params = {
  168. url: paramsUrl,
  169. method: 'GET'
  170. }
  171. this.sendReq(params, (res) => {
  172. _this.tableData = res.data.list
  173. _this.total = res.data.total
  174. // 表格斌值
  175. // if(_this.selectedRows.length > 0){
  176. // _this.selectedRows.forEach(row => {
  177. // this.$refs.multipleTable.toggleRowSelection(row,true);
  178. // });
  179. // }
  180. })
  181. },
  182. // 搜索
  183. onSubmit () {
  184. this.getTableData()
  185. },
  186. // 每页条数改变
  187. handleSizeChange (val) {
  188. this.pageSize = val
  189. this.getTableData()
  190. },
  191. // 当前页改变
  192. handleCurrentChange (val) {
  193. this.currentPage = val
  194. this.getTableData()
  195. },
  196. // 多选改变
  197. handleSelectionChange(val) {
  198. this.multipleSelection = val
  199. }
  200. }
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .product-select{
  205. .el-pagination{
  206. padding: 0px;
  207. margin-top: 30px;
  208. }
  209. .el-table{
  210. .img{
  211. width: 80px;
  212. height: 80px;
  213. }
  214. }
  215. }
  216. </style>