add.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view class="con">
  3. <view class="search ddflex">
  4. <image src="../../static/images/ssico.png" class="ssico"></image>
  5. <input @input="inputEvt" v-model="searchTitle" placeholder="搜索商品" placeholder-class="placeholder" class="ipt fflex" />
  6. <image v-if="searchTitle" src="../static/images/clear.png" class="clear" @click="clearTitle()"></image>
  7. </view>
  8. <view class="list" v-if="pageList.length > 0">
  9. <view class="li ddflex" v-for="(item, index) in pageList" :key="index">
  10. <image :src="item.pic" mode="aspectFill" class="pic"></image>
  11. <view class="fflex">
  12. <view class="title tovers">{{ item.title }}</view>
  13. <view class="money">¥{{ item.salePrice }}</view>
  14. </view>
  15. <view class="btn" @click="addProduct(item,index)">{{item.isAdd?'已添加':'添加'}}</view>
  16. </view>
  17. </view>
  18. <view class="nodata" v-if="ishow">
  19. <image :src="picUrlss + 'empty_sp.png'"></image>
  20. <text>暂无商品</text>
  21. </view>
  22. <view style="height: 100rpx;"></view>
  23. <view class="complete" @click="completeProduct()">完成</view>
  24. </view>
  25. </template>
  26. <script>
  27. const req = require('../../utils/request.js');
  28. export default {
  29. data() {
  30. return {
  31. picUrlss: req.public.picUrls,
  32. isLoad: true,
  33. searchTitle: '',
  34. form: {
  35. page: 1,
  36. limit: 10
  37. },
  38. pageList: [],
  39. productList: []
  40. };
  41. },
  42. onLoad() {
  43. //默认选中上面的标签
  44. let pages = getCurrentPages(); //获取所有页面栈实例列表
  45. let prevPage = pages[pages.length - 2]; //上一页页面实例
  46. this.productList = prevPage.$vm.productList;
  47. console.log('this.productList=',this.productList)
  48. this.getProductList();
  49. },
  50. onReachBottom() {
  51. this.form.page++;
  52. this.getProductList();
  53. },
  54. methods: {
  55. inputEvt(e) {
  56. this.form.page = 1;
  57. this.isLoad = true;
  58. this.getProductList();
  59. },
  60. clearTitle() {
  61. this.searchTitle = '';
  62. this.form.page = 1;
  63. this.isLoad = true;
  64. this.getProductList();
  65. },
  66. getProductList() {
  67. var that = this;
  68. if (!this.isLoad) return false;
  69. this.isLoad = false;
  70. if (this.searchTitle) {
  71. this.form.searchTitle = this.searchTitle;
  72. } else {
  73. this.form.searchTitle = '';
  74. }
  75. req.getRequest('/api/product/list', this.form, data => {
  76. data = data.map(it => {
  77. it.isAdd = false;
  78. this.productList.map(pit=>{
  79. if(it.id == pit.id){
  80. it.isAdd = true;
  81. }
  82. })
  83. if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs = true;
  84. return it;
  85. });
  86. if (data && data.length >= 10) {
  87. that.isLoad = true;
  88. }
  89. if (that.form.page > 1) data = that.pageList.concat(data);
  90. that.pageList = data;
  91. });
  92. },
  93. addProduct(item,index) {
  94. // if(item.isAdd) return false;
  95. this.pageList[index].isAdd = !this.pageList[index].isAdd;
  96. },
  97. completeProduct(){
  98. let list = this.pageList.filter(it=>{return it.isAdd});
  99. if(list.length > 3) return req.msg('最多可添加3个商品');
  100. let pages = getCurrentPages(); //获取所有页面栈实例列表
  101. let prevPage = pages[pages.length - 2]; //上一页页面实例
  102. prevPage.$vm.productList = list;
  103. // prevPage.$vm.productList.push(item); //修改上一页data里面的searchVal参数值为1211
  104. uni.navigateBack({
  105. //uni.navigateTo跳转的返回,默认1为返回上一级
  106. delta: 1
  107. });
  108. },
  109. }
  110. };
  111. </script>
  112. <style>
  113. @import './add.css';
  114. </style>