DGoodsList.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <template>
  2. <Container>
  3. <el-form slot="left" :inline="true" size="small" style="margin-bottom: 0">
  4. <el-form-item>
  5. <el-input
  6. v-model="search_form.keyword"
  7. style="width: 194px"
  8. placeholder="请输入商品名称"
  9. class="input-with-select"
  10. @keyup.enter.native="pageChange(1)"
  11. >
  12. <el-button
  13. slot="append"
  14. icon="el-icon-search"
  15. @click="pageChange(1)"
  16. ></el-button>
  17. </el-input>
  18. </el-form-item>
  19. <el-form-item>
  20. <GoodsCategory
  21. v-model="categoryPath"
  22. check-strictly
  23. clearable
  24. size="small"
  25. placeholder="商品分类"
  26. @change="categoryChange"
  27. />
  28. </el-form-item>
  29. <el-form-item>
  30. <el-select
  31. v-model="search_form.enableStatus"
  32. placeholder="商品状态"
  33. @change="pageChange(1)"
  34. >
  35. <el-option
  36. v-for="(item, index) in enableStatus_options"
  37. :key="index"
  38. :label="item.label"
  39. :value="item.value"
  40. ></el-option>
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item>
  44. <el-select
  45. v-model="search_form.isJoinCommission"
  46. placeholder="分销状态"
  47. style="width: 150px"
  48. @change="pageChange(1)"
  49. >
  50. <el-option
  51. v-for="(item, index) in join_options"
  52. :key="index"
  53. :label="item.label"
  54. :value="item.value"
  55. ></el-option>
  56. </el-select>
  57. </el-form-item>
  58. </el-form>
  59. <el-table
  60. ref="goodsTable"
  61. :data="goods_list"
  62. @selection-change="handleSelectionChange"
  63. @expand-change="goodsDetail"
  64. >
  65. <el-table-column
  66. align="center"
  67. type="selection"
  68. width="55"
  69. ></el-table-column>
  70. <el-table-column prop="title" label="商品" min-width="280">
  71. <template slot-scope="scope">
  72. <div class="clearfix">
  73. <div class="float_left">
  74. <el-image :src="scope.row.images[0]" fit="cover"></el-image>
  75. </div>
  76. <div class="float_left goods-name-view" style="margin-left: 10px">
  77. {{ scope.row.title }}
  78. </div>
  79. </div>
  80. </template>
  81. </el-table-column>
  82. <el-table-column
  83. v-if="specificationFlag"
  84. label="规格明细"
  85. width="100"
  86. type="expand"
  87. >
  88. <template slot-scope="scope">
  89. <ul class="sku-ul">
  90. <li
  91. v-for="(item, index) in scope.row.specMultiple"
  92. :key="index"
  93. class="sku-li"
  94. >
  95. <div class="clearfix">
  96. <div class="float_left">
  97. <el-image
  98. class="sku-img"
  99. fit="cover"
  100. :src="item.specImage || scope.row.images[0]"
  101. />
  102. </div>
  103. <div class="sku-info float_left">
  104. <p>
  105. <span class="label">规格:</span>
  106. {{ item.unitName }};
  107. <span
  108. v-for="(items, indexs) in item.specData"
  109. :key="indexs"
  110. >
  111. {{ items.specValueName }};
  112. </span>
  113. </p>
  114. <p>
  115. <span class="label">销售价:</span>
  116. {{ $_common.formattedNumber(item.price) }}
  117. </p>
  118. </div>
  119. </div>
  120. </li>
  121. </ul>
  122. </template>
  123. </el-table-column>
  124. <el-table-column
  125. v-if="commissionFlag"
  126. prop="commission"
  127. label="佣金"
  128. min-width="100"
  129. >
  130. <template slot-scope="scope">
  131. {{ $_common.formattedNumber(scope.row.commission) }}
  132. </template>
  133. </el-table-column>
  134. <el-table-column
  135. v-if="inventoryFlag"
  136. prop="inventoryTotal"
  137. label="库存"
  138. min-width="100"
  139. >
  140. <template slot-scope="scope">
  141. {{ $_common.formatNub(scope.row.inventoryTotal) }}
  142. </template>
  143. </el-table-column>
  144. <el-table-column
  145. v-if="salesVolumeFlag"
  146. prop="salesCount"
  147. label="销量"
  148. min-width="120"
  149. ></el-table-column>
  150. <el-table-column
  151. v-if="commodityFlag"
  152. prop="enableStatus"
  153. label="商品状态"
  154. min-width="120"
  155. >
  156. <template slot-scope="scope">
  157. <span v-if="scope.row.enableStatus === 5" class="success-status">
  158. 上架
  159. </span>
  160. <span v-else class="danger-status">下架</span>
  161. </template>
  162. </el-table-column>
  163. <el-table-column
  164. v-if="distributionFlag"
  165. prop="isJoinCommission"
  166. label="分销状态"
  167. min-width="100"
  168. >
  169. <template slot-scope="scope">
  170. <span v-if="scope.row.isJoinCommission === 5" class="success-status">
  171. 参与
  172. </span>
  173. <span v-else class="danger-status">不参与</span>
  174. </template>
  175. </el-table-column>
  176. <el-table-column
  177. v-if="
  178. $accessCheck($Access.DGoodsListsetCommission) ||
  179. $accessCheck($Access.DGoodsListupdateIsJoin)
  180. "
  181. prop="operation"
  182. label="操作"
  183. min-width="160"
  184. >
  185. <template slot="header" slot-scope="scope">
  186. <span v-if="false">{{ scope.$index }}</span>
  187. <span>操作</span>
  188. <el-popover popper-class="custom-table-checkbox" trigger="click">
  189. <el-checkbox-group v-model="checkList">
  190. <el-checkbox
  191. v-for="(item, index) in columns"
  192. :key="index"
  193. :label="item.label"
  194. @change="change"
  195. ></el-checkbox>
  196. </el-checkbox-group>
  197. <el-button
  198. slot="reference"
  199. icon="el-icon-setting"
  200. type="text"
  201. ></el-button>
  202. </el-popover>
  203. </template>
  204. <template slot-scope="scope">
  205. <el-button
  206. v-if="$accessCheck($Access.DGoodsListsetCommission)"
  207. type="text"
  208. @click="$router.push(`/Distribution/SetCommission/${scope.row.id}`)"
  209. >
  210. 设置佣金
  211. </el-button>
  212. <el-button
  213. v-if="$accessCheck($Access.DGoodsListupdateIsJoin)"
  214. type="text"
  215. @click="
  216. updateIsJoin(scope.row, scope.row.isJoinCommission === 5 ? 4 : 5)
  217. "
  218. >
  219. {{ scope.row.isJoinCommission === 5 ? "不参与" : "参与" }}
  220. </el-button>
  221. </template>
  222. </el-table-column>
  223. </el-table>
  224. <FooterPage
  225. :page-size="pageSize"
  226. :total-page.sync="total"
  227. :current-page.sync="page"
  228. @pageChange="pageChange"
  229. @sizeChange="sizeChange"
  230. >
  231. <div
  232. v-if="$accessCheck($Access.DGoodsListupdateIsJoin)"
  233. slot="btn-div"
  234. class="foot-btn-div"
  235. >
  236. <span class="batch-checkbox">
  237. <el-checkbox
  238. v-model="checkedAll"
  239. @change="checkAllChange"
  240. ></el-checkbox>
  241. </span>
  242. <el-dropdown>
  243. <el-button size="mini">
  244. 批量设置分销
  245. <i class="el-icon-caret-top"></i>
  246. </el-button>
  247. <el-dropdown-menu slot="dropdown">
  248. <el-dropdown-item>
  249. <div class="dropdown-div" @click="updateIsJoin(choose_data, 5)">
  250. 参与
  251. </div>
  252. </el-dropdown-item>
  253. <el-dropdown-item>
  254. <div class="dropdown-div" @click="updateIsJoin(choose_data, 4)">
  255. 不参与
  256. </div>
  257. </el-dropdown-item>
  258. </el-dropdown-menu>
  259. </el-dropdown>
  260. <!-- <el-button-->
  261. <!-- size="mini"-->
  262. <!-- plain-->
  263. <!-- type="primary"-->
  264. <!-- @click="show_set = true"-->
  265. <!-- >-->
  266. <!-- 设置佣金-->
  267. <!-- </el-button>-->
  268. </div>
  269. </FooterPage>
  270. <el-dialog
  271. :close-on-press-escape="false"
  272. :close-on-click-modal="false"
  273. title="设置佣金"
  274. :visible.sync="show_set"
  275. width="30%"
  276. >
  277. <div>
  278. <span style="margin-right: 10px">批量设置佣金:</span>
  279. <el-input v-model="set_form.ratio" style="width: 150px" size="small">
  280. <span slot="append">%</span>
  281. </el-input>
  282. <el-input v-model="set_form.money" size="small" style="width: 150px">
  283. <span slot="append">元</span>
  284. </el-input>
  285. </div>
  286. <span slot="footer" class="dialog-footer">
  287. <el-button @click="show_set = false">取 消</el-button>
  288. <el-button type="primary" @click="setCommission">确 定</el-button>
  289. </span>
  290. </el-dialog>
  291. </Container>
  292. </template>
  293. <script>
  294. import GoodsCategory from "@/component/common/GoodsCategory.vue";
  295. import {
  296. CommissionGoodsGetInfo,
  297. CommissionGoodsGetAll,
  298. updateIsJoin,
  299. } from "@/api/Commission";
  300. export default {
  301. name: "DGoodsList",
  302. components: {
  303. GoodsCategory,
  304. },
  305. data() {
  306. return {
  307. show_set: false,
  308. checkedAll: false,
  309. set_form: {
  310. ratio: "",
  311. money: "",
  312. },
  313. categoryPath: [],
  314. search_form: {
  315. keyword: "",
  316. categoryId: "",
  317. enableStatus: "", // 上下架状态
  318. isJoinCommission: "", // 是否参与分销 5是 4否
  319. },
  320. enableStatus_options: [
  321. {
  322. value: 5,
  323. label: "上架",
  324. },
  325. {
  326. value: 4,
  327. label: "下架",
  328. },
  329. ],
  330. join_options: [
  331. {
  332. value: 5,
  333. label: "参与",
  334. },
  335. {
  336. value: 4,
  337. label: "不参与",
  338. },
  339. ],
  340. total: 0,
  341. page: 1,
  342. pageSize: 10,
  343. goods_list: [],
  344. choose_data: [],
  345. specMultiple: [],
  346. specMultipleLoad: false,
  347. checkList: ["规格明细", "佣金", "库存", "销量", "商品状态", "分销状态"],
  348. columns: [
  349. {
  350. label: "规格明细",
  351. },
  352. {
  353. label: "佣金",
  354. },
  355. {
  356. label: "库存",
  357. },
  358. {
  359. label: "销量",
  360. },
  361. {
  362. label: "商品状态",
  363. },
  364. {
  365. label: "分销状态",
  366. },
  367. ],
  368. specificationFlag: true,
  369. commissionFlag: true,
  370. inventoryFlag: true,
  371. salesVolumeFlag: true,
  372. commodityFlag: true,
  373. distributionFlag: true,
  374. };
  375. },
  376. created() {
  377. this.CommissionGoodsGetAll();
  378. },
  379. activated() {
  380. if (this.$_isInit()) return;
  381. this.CommissionGoodsGetAll();
  382. },
  383. methods: {
  384. async goodsDetail(row) {
  385. if (!row.specMultiple.length) {
  386. const index = this.goods_list.findIndex((item) => item.id === row.id);
  387. const { data } = await CommissionGoodsGetInfo(row.id);
  388. this.goods_list[index].specMultiple = data.specMultiple;
  389. }
  390. },
  391. categoryChange(val) {
  392. if (val.length) {
  393. this.search_form.categoryId = val[val.length - 1];
  394. } else {
  395. this.search_form.categoryId = [];
  396. }
  397. this.pageChange(1);
  398. },
  399. async CommissionGoodsGetAll() {
  400. const { data, pageTotal } = await CommissionGoodsGetAll({
  401. page: this.page,
  402. pageSize: this.pageSize,
  403. ...this.search_form,
  404. });
  405. this.goods_list = data.map((item) => {
  406. return {
  407. ...item,
  408. specMultiple: [],
  409. };
  410. });
  411. this.total = pageTotal;
  412. for (let i = 0; i < this.goods_list.length; i++) {
  413. const isTrue = this.choose_data.find((itemF) => {
  414. return itemF.id === this.goods_list[i].id;
  415. });
  416. if (isTrue) {
  417. this.toggleRowSelection([this.goods_list[i]]);
  418. }
  419. }
  420. },
  421. // 批量选择
  422. handleSelectionChange(val) {
  423. if (val.length) {
  424. if (!this.choose_data.length) {
  425. this.choose_data = val;
  426. } else {
  427. this.choose_data = this.$_common.unique(
  428. this.choose_data.concat(val),
  429. ["id"]
  430. );
  431. }
  432. } else {
  433. for (let i = 0; i < this.goods_list.length; i++) {
  434. const index = this.choose_data.findIndex((itemF) => {
  435. return itemF.id === this.goods_list[i].id;
  436. });
  437. if (index > -1) {
  438. this.choose_data.splice(index, 1);
  439. }
  440. }
  441. }
  442. this.checkedAll = val.length >= this.goods_list.length;
  443. },
  444. // 切页
  445. pageChange(val) {
  446. this.page = val;
  447. this.CommissionGoodsGetAll();
  448. },
  449. // 每页数据大小改变
  450. sizeChange(val) {
  451. this.page = 1;
  452. this.pageSize = val;
  453. this.CommissionGoodsGetAll();
  454. },
  455. updateIsJoin(rows, isJoinCommission) {
  456. let ids = [];
  457. if (Array.isArray(rows)) {
  458. ids = rows.map((item) => {
  459. return item.id;
  460. });
  461. } else {
  462. ids = [rows.id];
  463. }
  464. if (!ids.length) {
  465. this.$message.warning("至少要选择一个商品");
  466. return;
  467. }
  468. this.$confirm("是否设置商品参与分销?", "提示", {
  469. confirmButtonText: "确定",
  470. cancelButtonText: "取消",
  471. type: "warning",
  472. }).then(async () => {
  473. const data = await updateIsJoin({
  474. id: ids,
  475. isJoinCommission: isJoinCommission,
  476. });
  477. this.$message.success("操作成功");
  478. this.CommissionGoodsGetAll();
  479. });
  480. },
  481. async setCommission() {
  482. this.show_set = false;
  483. },
  484. toggleRowSelection(rows) {
  485. this.$nextTick(() => {
  486. rows.forEach((row) => {
  487. this.$refs.goodsTable.toggleRowSelection(row, true);
  488. });
  489. });
  490. },
  491. checkAllChange() {
  492. this.$refs.goodsTable.toggleAllSelection();
  493. },
  494. change() {
  495. this.specificationFlag = this.checkList.some(
  496. (item) => item === "规格明细"
  497. );
  498. this.commissionFlag = this.checkList.some((item) => item === "佣金");
  499. this.inventoryFlag = this.checkList.some((item) => item === "库存");
  500. this.salesVolumeFlag = this.checkList.some((item) => item === "销量");
  501. this.commodityFlag = this.checkList.some((item) => item === "商品状态");
  502. this.distributionFlag = this.checkList.some(
  503. (item) => item === "分销状态"
  504. );
  505. },
  506. },
  507. };
  508. </script>
  509. <style scoped lang="scss">
  510. .goods-name-view {
  511. width: calc(100% - 76px);
  512. margin-left: 10px;
  513. }
  514. .goods-title {
  515. width: 100%;
  516. overflow: hidden;
  517. text-overflow: ellipsis;
  518. display: -webkit-box;
  519. -webkit-box-orient: vertical;
  520. -webkit-line-clamp: 2;
  521. }
  522. .all-handel-label {
  523. color: #666;
  524. font-size: 12px;
  525. }
  526. .custom-table-checkbox {
  527. .el-checkbox {
  528. display: block !important;
  529. margin: 0 05px 0;
  530. }
  531. }
  532. .sku-ul {
  533. .sku-li {
  534. display: inline-block;
  535. margin-right: 10px;
  536. border: 1px solid #ebeef5;
  537. padding: 10px;
  538. width: 294px;
  539. vertical-align: middle;
  540. .sku-img {
  541. width: 50px;
  542. height: 50px;
  543. border-radius: 2px;
  544. margin-right: 8px;
  545. }
  546. .sku-info {
  547. line-height: 23px;
  548. color: #111111;
  549. .label {
  550. display: inline-block;
  551. width: 50px;
  552. color: #666666;
  553. text-align: right;
  554. }
  555. }
  556. }
  557. }
  558. </style>