index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="container">
  3. <view class="search"><search></search></view>
  4. <shop-item v-for="(item, index) in shopList" :key="index" :itemObject="item" @handleMethod="handleMethod"></shop-item>
  5. </view>
  6. </template>
  7. <script>
  8. // +----------------------------------------------------------------------
  9. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  10. // +----------------------------------------------------------------------
  11. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  12. // +----------------------------------------------------------------------
  13. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  14. // +----------------------------------------------------------------------
  15. // | Author: CRMEB Team <admin@crmeb.com>
  16. // +----------------------------------------------------------------------
  17. import shopItem from '../components/shopItem.vue';
  18. import search from '../components/search.vue';
  19. import { productLstApi, productDestory, productRestore } from 'api/product.js';
  20. import { Toast, Modal } from 'libs/uniApi.js';
  21. export default {
  22. components: {
  23. shopItem,
  24. search
  25. },
  26. data() {
  27. return {
  28. merId: '',
  29. where: {
  30. page: 1,
  31. limit: 15
  32. },
  33. shopList: [],
  34. selectMenuId: 5
  35. };
  36. },
  37. onLoad(opt) {
  38. this.merId = opt.mer_id;
  39. this.initData();
  40. },
  41. // 下拉到底部
  42. onReachBottom() {
  43. this.where.page++;
  44. this.initData('concat');
  45. },
  46. methods: {
  47. initData(type) {
  48. productLstApi(this.merId, { ...this.where, type: this.selectMenuId }).then(res => {
  49. if (type == 'concat') {
  50. this.shopList = this.shopList.concat(res.data.list);
  51. } else {
  52. this.shopList = res.data.list;
  53. }
  54. // 给每一个列表项,添加可用功能
  55. this.shopList.forEach(item => {
  56. this.$set(item, 'handleList', [
  57. {
  58. id: 1,
  59. label: '删除'
  60. },
  61. {
  62. id: 2,
  63. label: '还原'
  64. }
  65. ]);
  66. });
  67. });
  68. },
  69. // 彻底删除
  70. handleProductDestory(obj, index) {
  71. Modal('温馨提示', `商品"${obj.store_name}", 将被彻底删除,请问是否继续`).then(() => {
  72. productDestory(this.merId, obj.product_id).then(res => {
  73. this.$util.Tips({ title: res.message, icon: 'success' });
  74. this.shopList.splice(index, 1);
  75. })
  76. })
  77. },
  78. // 还原
  79. handleProductRestore(obj, index) {
  80. Modal('温馨提示', `商品"${obj.store_name}",将被还原,请问是否继续`).then(() => {
  81. productRestore(this.merId, obj.product_id).then(res => {
  82. this.$util.Tips({ title: res.message, icon: 'success' });
  83. this.shopList.splice(index, 1);
  84. })
  85. })
  86. },
  87. handleMethod(item, obj, index) {
  88. if(item.id == 1) {
  89. this.handleProductDestory(obj, index);
  90. return;
  91. }
  92. if(item.id == 2) {
  93. this.handleProductRestore(obj, index);
  94. }
  95. console.log(item, obj);
  96. }
  97. }
  98. };
  99. </script>
  100. <style lang="scss" scoped>
  101. .search {
  102. padding: 30rpx 25rpx;
  103. background: #fff;
  104. }
  105. </style>