subShopGoods.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <!-- -->
  2. <template>
  3. <div>
  4. <save-form
  5. :inline="true"
  6. class="searchForm"
  7. ref="searchForm"
  8. @submit="onSearch"
  9. @reset="onReset"
  10. :model="searchForm"
  11. save-key="subShopGoods"
  12. >
  13. <el-form-item prop="keyword">
  14. <el-input
  15. v-model.trim="searchForm.keyword"
  16. clearable
  17. placeholder="商品名称"
  18. ></el-input>
  19. </el-form-item>
  20. <el-form-item prop="productSn">
  21. <el-input
  22. v-model.trim="searchForm.productSn"
  23. clearable
  24. placeholder="商品货号"
  25. ></el-input>
  26. </el-form-item>
  27. <el-form-item prop="productCategoryId">
  28. <!-- <el-select
  29. v-model.trim="searchForm.productCategoryId"
  30. clearable
  31. placeholder="商品分类"
  32. >
  33. <el-option
  34. v-for="item in categoryList"
  35. :key="item.value"
  36. :label="item.label"
  37. :value="item.value"
  38. >
  39. </el-option>
  40. </el-select> -->
  41. <el-cascader
  42. v-model.trim="searchForm.productCategoryId"
  43. :options="categoryList"
  44. placeholder="商品分类"
  45. :props="{ expandTrigger: 'hover' }"
  46. ></el-cascader>
  47. <!-- checkStrictly: true, -->
  48. </el-form-item>
  49. <el-form-item prop="brandId">
  50. <el-select
  51. v-model.trim="searchForm.brandId"
  52. clearable
  53. placeholder="商品品牌"
  54. >
  55. <el-option
  56. v-for="(item, index) in goodsBrand"
  57. :key="index"
  58. :label="item.label"
  59. :value="item.value"
  60. ></el-option>
  61. </el-select>
  62. </el-form-item>
  63. <el-form-item prop="publishStatus">
  64. <el-select
  65. v-model.trim="searchForm.publishStatus"
  66. clearable
  67. placeholder="上架状态"
  68. >
  69. <el-option label="上架" :value="1"></el-option>
  70. <el-option label="下架" :value="0"></el-option>
  71. </el-select>
  72. </el-form-item>
  73. <el-form-item>
  74. <el-button type="danger" native-type="submit">搜索</el-button>
  75. <el-button type="primary" native-type="reset">重置</el-button>
  76. </el-form-item>
  77. </save-form>
  78. <div class="tableWrap">
  79. <el-table
  80. :data="tableList"
  81. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  82. @selection-change="handleSelectionChange"
  83. @select="onTableSelect"
  84. ref="multipleSelection"
  85. >
  86. <el-table-column
  87. type="selection"
  88. width="55"
  89. :selectable="onSelectable"
  90. ></el-table-column>
  91. <el-table-column
  92. align="center"
  93. prop="name"
  94. label="商品名称"
  95. width="200px"
  96. >
  97. <template slot-scope="scope">
  98. <tooltip :content="scope.row.name" />
  99. </template>
  100. </el-table-column>
  101. <el-table-column align="center" prop="productSn" label="商品货号">
  102. </el-table-column>
  103. <el-table-column align="center" prop="brandName" label="品牌">
  104. </el-table-column>
  105. <el-table-column align="center" prop="skuCode" label="sku编号">
  106. </el-table-column>
  107. <el-table-column align="center" prop="price" label="销售价格">
  108. </el-table-column>
  109. <el-table-column align="center" prop="stock" label="剩余库存">
  110. </el-table-column>
  111. <!-- <el-table-column align="center" prop="price" label="采购价">
  112. </el-table-column> -->
  113. <el-table-column align="center" prop="publishStatus" label="状态">
  114. <template slot-scope="scope">
  115. <el-tag :type="scope.row.publishStatus == 1 ? '' : 'danger'">
  116. {{ scope.row.publishStatus ? "上架" : "下架" }}
  117. </el-tag>
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. <pagination
  122. sync
  123. save-key="subShopGoods"
  124. :total.sync="pageInfo.total"
  125. :page.sync="pageInfo.page"
  126. :limit.sync="pageInfo.limit"
  127. :page-sizes="pageInfo.page_size"
  128. @pagination="getList"
  129. />
  130. </div>
  131. <div class="dialog-footer">
  132. <el-button @click="onClose()">取 消</el-button>
  133. <el-button type="primary" @click="onSubmit()">确 定</el-button>
  134. </div>
  135. </div>
  136. </template>
  137. <script>
  138. import pagination from "@/components/Pagination/index";
  139. import {
  140. api_queryGoodsSubByPage,
  141. api_queryGoodsCategoryList
  142. } from "@/api/businessManager";
  143. export default {
  144. props: ["disabledIds", "goodsBrand"],
  145. components: {
  146. pagination
  147. },
  148. data() {
  149. return {
  150. categoryList: [],
  151. pageInfo: {
  152. // 分页规则
  153. limit: 10, // 限制显示条数
  154. page: 1, // 当前页
  155. total: 0, // 总条数
  156. page_size: [10, 20, 40, 50] // 选择限制显示条数
  157. },
  158. searchForm: {
  159. keyword: null,
  160. productSn: null,
  161. publishStatus: null,
  162. productCategoryId: null,
  163. brandId: null
  164. },
  165. tableList: [],
  166. isNewPage: false,
  167. selectList: []
  168. };
  169. },
  170. //生命周期 - 挂载完成(可以访问DOM元素)
  171. mounted() {
  172. this.__init();
  173. this.getList();
  174. },
  175. methods: {
  176. async __init() {
  177. let params = {
  178. delFlag: 0,
  179. rows: 9999
  180. };
  181. try {
  182. const { data } = await api_queryGoodsCategoryList(params);
  183. const result = data || [];
  184. let tempArray = [];
  185. result.forEach(row => {
  186. let children = [];
  187. if (row.children && row.children.length > 0) {
  188. row.children.forEach(child => {
  189. children.push({
  190. label: child.name,
  191. value: child.id
  192. });
  193. });
  194. }
  195. tempArray.push({
  196. label: row.name,
  197. value: row.id,
  198. children
  199. });
  200. });
  201. this.categoryList = tempArray;
  202. } catch {}
  203. },
  204. getList() {
  205. let params = Object.assign({}, this.searchForm);
  206. // params.organId = this.organId;
  207. params.rows = this.pageInfo.limit;
  208. params.page = this.pageInfo.page;
  209. params.productCategoryId = params.productCategoryId
  210. ? params.productCategoryId[params.productCategoryId.length - 1]
  211. : null;
  212. api_queryGoodsSubByPage(params).then(res => {
  213. if (res.code == 200 && res.data) {
  214. this.tableList = res.data.rows;
  215. this.pageInfo.total = res.data.total;
  216. let idList = this.selectList.map(group => {
  217. return group.skuStockId;
  218. });
  219. this.isNewPage = true;
  220. this.$nextTick(() => {
  221. this.tableList.forEach(course => {
  222. if (idList.indexOf(course.skuStockId) != -1) {
  223. this.$refs.multipleSelection.toggleRowSelection(course, true);
  224. }
  225. });
  226. this.isNewPage = false;
  227. });
  228. }
  229. });
  230. },
  231. onSearch() {
  232. this.pageInfo.page = 1;
  233. this.getList();
  234. },
  235. onReset() {
  236. // 重置
  237. this.$refs.searchForm.resetFields();
  238. this.getList();
  239. },
  240. onClose() {
  241. this.$listeners.close();
  242. },
  243. onSubmit() {
  244. this.$listeners.comfirm(this.selectList);
  245. this.onClose();
  246. },
  247. onSelectable(row) {
  248. return !this.disabledIds.includes(row.skuStockId);
  249. },
  250. handleSelectionChange(arr) {
  251. if (arr.length > 0) {
  252. // 有可能加 有可能减
  253. this.selectList = this.selectList.concat(arr);
  254. // 去重
  255. this.selectList = this.$helpers.lodash.uniqBy(
  256. this.selectList,
  257. "skuStockId"
  258. );
  259. }
  260. // else if(){}
  261. else {
  262. if (this.isNewPage) return;
  263. // 有2种 1是新页
  264. // 2是点击反选
  265. let idList = this.selectList.map(course => {
  266. return course.skuStockId;
  267. });
  268. this.$nextTick(() => {
  269. let tableIdList = [];
  270. this.tableList.forEach(course => {
  271. tableIdList.push(course.skuStockId);
  272. if (idList.indexOf(course.skuStockId) != -1) {
  273. this.$refs.tableList.toggleRowSelection(course, false);
  274. // 删除这个元素
  275. }
  276. });
  277. this.selectList = this.$helpers.lodash.remove(
  278. this.selectList,
  279. function(item) {
  280. return tableIdList.indexOf(item.skuStockId) == -1;
  281. }
  282. );
  283. if (this.selectList.length <= 0) {
  284. this.clearCom();
  285. }
  286. });
  287. }
  288. },
  289. onTableSelect(rows, row) {
  290. let idList = this.selectList.map(course => {
  291. return course.skuStockId;
  292. });
  293. if (idList.indexOf(row.skuStockId) != -1) {
  294. this.selectList.splice(idList.indexOf(row.skuStockId), 1);
  295. if (this.selectList.length <= 0) {
  296. this.clearCom();
  297. }
  298. }
  299. },
  300. clearCom() {
  301. // this.selectList = [];
  302. // this.$refs.multipleSelection.clearSelection();
  303. }
  304. }
  305. };
  306. </script>
  307. <style lang="less" scoped>
  308. .dialog-footer {
  309. padding-top: 20px;
  310. width: 100%;
  311. text-align: center;
  312. }
  313. </style>