myfocus.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view class="pages">
  3. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  4. <view class="product-wrap">
  5. <uni-swipe-action>
  6. <view v-for="(item,index) in productlist" :key="index" class="product-item">
  7. <!-- <uni-swipe-action-item :right-options="swipeOptions" @click="delItem(item.id)" @change="changeSwipe"> -->
  8. <view class="product-item-img-wrap" @click="productclick(item.pmsProduct.id)">
  9. <image class="product-item-img" :src="$getimg+item.pmsProduct.pic" mode="widthFix"></image>
  10. </view>
  11. <view class="product-item-info" @click="productclick(item.pmsProduct.id)">
  12. <view class="product-item-til">{{item.productName}}</view>
  13. <view class="product-item-brand">{{item.productBrand}} <text class="postage" v-if="item.postage">包邮</text></view>
  14. <view class="product-item-addr">{{item.addr}}</view>
  15. <view class="product-item-company">{{item.companyName}}</view>
  16. <view class="product-item-price"><text class="rmb">¥</text> <text class="price">{{item.pmsProduct.price}}</text> / {{item.pmsProduct.unit}}</view>
  17. </view>
  18. <!-- </uni-swipe-action-item> -->
  19. </view>
  20. </uni-swipe-action>
  21. </view>
  22. </mescroll-body>
  23. </view>
  24. </template>
  25. <script>
  26. // 引入mescroll-mixins.js
  27. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  28. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  29. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  30. import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue';
  31. import uniSwipeActionItem from '@/components/uni-swipe-action-item/uni-swipe-action-item.vue';
  32. export default {
  33. mixins: [MescrollMixin], // 使用mixin
  34. components: {
  35. MescrollBody,
  36. uniSwipeAction,
  37. uniSwipeActionItem
  38. },
  39. data() {
  40. return {
  41. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  42. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  43. downOption: {
  44. // ...
  45. },
  46. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  47. upOption: {
  48. page: {
  49. size: 10 // 每页数据的数量,默认10
  50. },
  51. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  52. empty: {
  53. tip: '暂无相关数据'
  54. }
  55. },
  56. params:{
  57. tokenhead:'',
  58. token:'',
  59. },
  60. productlist:[
  61. // {
  62. // img:"http://placekitten.com/160/160",
  63. // title:'红球源500ml*2瓶装传统精炼纯正山茶油',
  64. // brand:'红球源',
  65. // postage:true,
  66. // addr:'贵州大亨油茶科技有限公司',
  67. // price:'258',
  68. // unit:'盒'
  69. // },
  70. // {
  71. // img:"http://placekitten.com/160/160",
  72. // title:'红球源500ml*2瓶装传统精炼纯正山茶油',
  73. // brand:'红球源',
  74. // postage:true,
  75. // addr:'贵州大亨油茶科技有限公司',
  76. // price:'258',
  77. // unit:'盒'
  78. // }
  79. ],
  80. swipeOptions:[
  81. {
  82. text: '删除',
  83. style: {
  84. backgroundColor: '#dd524d'
  85. }
  86. }
  87. ],
  88. }
  89. },
  90. onShow() {
  91. let serf = this;
  92. // //检查登录,获取token
  93. // let loginRes = this.checkLogin('/pages/index/index', '2');
  94. // if(!loginRes){return false;}
  95. // serf.params.token=loginRes[0];
  96. },
  97. onLoad() {
  98. let self = this;
  99. uni.getStorage({
  100. key:'token',
  101. success: function (res) {
  102. self.params.token = res.data;
  103. // console.log(res.data);
  104. }
  105. });
  106. uni.getStorage({
  107. key:'tokenhead',
  108. success: function (res) {
  109. self.params.tokenhead = res.data;
  110. // console.log(res.data);
  111. }
  112. });
  113. },
  114. methods: {
  115. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  116. mescrollInit(mescroll) {
  117. this.mescroll = mescroll;
  118. },
  119. /*下拉刷新的回调, 有三种处理方式:*/
  120. downCallback(){
  121. // 第2种: 下拉刷新和上拉加载调同样的接口, 那么不用第1种方式, 直接mescroll.resetUpScroll()即可
  122. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  123. },
  124. /*上拉加载的回调*/
  125. upCallback(page) {
  126. let pageNum = page.num; // 页码, 默认从1开始
  127. let pageSize = page.size; // 页长, 默认每页10条
  128. this.params = Object.assign(this.params,{pageNO:pageNum,pageSize:pageSize});
  129. let thetoken = this.params.tokenhead + this.params.token;
  130. console.log('thetoken',thetoken);
  131. this.$api.http.get(this.config.apiBaseurl+'/pre/other',{params:this.params,header: {Authorization:thetoken}}).then(data => {
  132. console.log('1111111111',data);
  133. if(data.data.code=='1001'){
  134. // uni.redirectTo({
  135. // url:'/pages/login/login?backpage=/pages/index/index'+'&backtype='+2,
  136. // });
  137. };
  138. console.log('data',JSON.parse(JSON.stringify(data)));
  139. // 接口返回的当前页数据列表 (数组)
  140. let curPageData = data.data.data.list;
  141. // console.log('curPageData',curPageData);
  142. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  143. let curPageLen = curPageData.length;
  144. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  145. let totalPage =data.data.data.totalPage;
  146. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  147. let totalSize = data.data.data.total;
  148. // this.productlist = curPageData;
  149. // 接口返回的是否有下一页 (true/false)
  150. // let hasNext = data.xxx;
  151. //设置列表数据
  152. if(page.num == 1) this.productlist = []; //如果是第一页需手动置空列表
  153. this.productlist = this.productlist.concat(curPageData); //追加新数据
  154. // console.log('page.num',page.num);
  155. console.log('this.productlist',JSON.parse(JSON.stringify(this.productlist)));
  156. // 请求成功,隐藏加载状态
  157. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  158. this.mescroll.endByPage(curPageLen, totalPage);
  159. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  160. // this.mescroll.endBySize(curPageLen, totalSize);
  161. // setTimeout(()=>{
  162. // this.mescroll.endSuccess(curPageLen)
  163. // },20)
  164. }).catch(err => {
  165. this.mescroll.endErr()
  166. console.log(err)
  167. });
  168. },
  169. //产品点击
  170. productclick(id){
  171. uni.navigateTo({
  172. url:`/pages/product/product?id=${id}`,
  173. })
  174. },
  175. //滑动change事件
  176. changeSwipe(e){
  177. console.log(e)
  178. },
  179. delItem(id){
  180. console.log(id);
  181. }
  182. }
  183. }
  184. </script>
  185. <style scoped>
  186. /* @import url("./mypublish.css"); */
  187. /* .product-item{display: block;} */
  188. </style>