index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <!-- z-paging插件:具体使用文档请看https://z-paging.zxlee.cn/ -->
  3. <z-paging
  4. auto-show-back-to-top
  5. back-to-top-bottom="300rpx"
  6. :paging-style="{ paddingBottom: 'constant(safe-area-inset-bottom)', paddingBottom: 'env(safe-area-inset-bottom)' }"
  7. ref="paging"
  8. v-model="dataList"
  9. @query="queryList"
  10. >
  11. <template #top>
  12. <view class="c-bg-f"><u-tabs :activeStyle="{ color: '#3c9cff' }" :list="statusList" @click="statusClick"></u-tabs></view>
  13. </template>
  14. <view class="o-plr-24 o-ptb-24">
  15. <view v-for="(item, index) in dataList" :key="item.id" class="l-boxShadow o-mb-20 c-bg-f o-plr-24 o-ptb-12 c-radius-10">
  16. <view class="l-flex-between o-ptb-20">
  17. <view class="c-color-8 l-flex-RC">
  18. <text>取餐号:</text>
  19. <u-tooltip color="#888888" overlay :text="mealCode(item.id)" direction="bottom"></u-tooltip>
  20. </view>
  21. </view>
  22. <view class="l-flex-between o-ptb-20">
  23. <view class="c-color-8 l-flex-RC">
  24. <text>订单号:</text>
  25. <u-tooltip color="#888888" overlay :text="item.sn" direction="bottom"></u-tooltip>
  26. </view>
  27. <text class="c-color-8">{{ statusName(item.status) }}</text>
  28. </view>
  29. <u-line></u-line>
  30. <view @click="toDetail(item)" v-for="item1 in item.goodsNumsPrice">
  31. <view class="l-flex-RC o-mb-20">
  32. <view class="l-flex-1">
  33. <!-- 后台约定好A00,但是这个商品编号有可能会获取不到,获取不到会是A00 -->
  34. <u--image
  35. v-if="item1.imgId !== 'A00'"
  36. :width="GETT_miniProduct.includes(item1.imgId) ? '250rpx' : '200rpx'"
  37. :height="GETT_miniProduct.includes(item1.imgId) ? '250rpx' : '200rpx'"
  38. mode="aspectFit"
  39. :lazy-load="true"
  40. :fade="true"
  41. duration="450"
  42. :src="item1.imgUrl"
  43. >
  44. <view slot="error" style="font-size: 24rpx;">加载失败</view>
  45. </u--image>
  46. </view>
  47. <view class="l-flex-3">
  48. <view class="c-color-8 u-line-2">{{ item1.goodsName }}</view>
  49. <view class="l-flex-RC o-mt-30">
  50. <text class="c-color-8">X{{ item1.nums }}</text>
  51. <text class="c-color-MR o-ml-30">¥{{ item1.price }}</text>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <u-line></u-line>
  57. <view class="l-flex-between o-ptb-20">
  58. <text class="c-text-12 c-color-8">{{ new Date(item.payDate).getTime() | date('yyyy-mm-dd hh:MM:ss') }}</text>
  59. <view class="l-flex-RC">
  60. <text class="c-text-12 c-color-8">共{{ item.goodsNums }}件商品</text>
  61. <view class="l-flex-RC o-ml-30">
  62. <text class="c-text-12 c-color-8">实付</text>
  63. <text class="c-text-16 c-color-MR">¥{{ item.price }}</text>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </z-paging>
  70. </template>
  71. <script>
  72. // 导入接口
  73. import { API_getOrderlist } from '@/common/api.js';
  74. // 引入辅助函数
  75. import { mapGetters } from 'vuex';
  76. // 引入商品数据
  77. import goodsList from '@/static/images/home/goods.js';
  78. export default {
  79. data() {
  80. return {
  81. // z-paging插件的主数据,用作列表渲染
  82. dataList: [],
  83. // 标签数组,元素为对象,如[{name: '推荐'}]
  84. statusList: [
  85. {
  86. name: '已完成'
  87. },
  88. {
  89. name: '已退款'
  90. }
  91. ],
  92. // 当前选中标签的索引
  93. current: 0
  94. };
  95. },
  96. computed: {
  97. // 使用辅助函数
  98. ...mapGetters(['GETT_loginInfos', 'GETT_miniProduct']),
  99. // 状态名称
  100. statusName: () => {
  101. return status => {
  102. switch (status) {
  103. case 1:
  104. return '已完成';
  105. break;
  106. case 3:
  107. return '已退款';
  108. break;
  109. default:
  110. return '暂无';
  111. break;
  112. }
  113. };
  114. },
  115. mealCode: () => {
  116. return id => {
  117. return id.substring(id.length-6,id.length);
  118. };
  119. }
  120. },
  121. methods: {
  122. // 点击去详情页
  123. toDetail(row) {
  124. this.$M_Go(`/otherPages/mine/orderRecord/detail?row=${encodeURIComponent(JSON.stringify(row))}`);
  125. },
  126. // z-paging插件分页的方法
  127. queryList(pageNo, pageSize) {
  128. let param = {
  129. wxId: this.GETT_loginInfos.id,
  130. status: this.current === 0 ? 1 : 3,
  131. size: pageSize,
  132. current: pageNo
  133. };
  134. // 发起获取商品类表请求
  135. API_getOrderlist(param).then(res => {
  136. const { records } = res || [];
  137. if (records.length > 0) {
  138. records.forEach(item => {
  139. // 将不同品种的商品分隔出来
  140. let noteList = item.note.split(',');
  141. // 商品名称、数量、价格组成
  142. item.goodsNumsPrice = [];
  143. // 商品总数量
  144. item.goodsNums = 0;
  145. if (noteList.length > 0) {
  146. noteList.forEach((item1, index) => {
  147. // 处理数组中有null,undefined,''的情况
  148. if (item1) {
  149. item.goodsNumsPrice[index] = {};
  150. // 将商品名称和商品数量、商品价格分隔出俩
  151. let goodsNumsPrice = item1.split('-');
  152. // 组合商品编码
  153. item.goodsNumsPrice[index]['imgId'] = goodsNumsPrice[0];
  154. // 组合商品名称
  155. item.goodsNumsPrice[index]['goodsName'] = goodsNumsPrice[1];
  156. let numsPrice = goodsNumsPrice[2].split(':');
  157. // 组合价格
  158. item.goodsNumsPrice[index]['nums'] = numsPrice[0];
  159. // 组合数量
  160. item.goodsNumsPrice[index]['price'] = numsPrice[1];
  161. // 商品总数量
  162. item.goodsNums = this.$M_Big(item.goodsNums).add(numsPrice[0]);
  163. }
  164. });
  165. }
  166. });
  167. // 从商品列表中找到对应的商品路径(因为商品图片是存到前台的,要根据后台的标识找到路径)
  168. goodsList.forEach(item => {
  169. records.forEach(item1 => {
  170. // 给前台数据赋值接口数组
  171. if (item1.goodsNumsPrice.length > 0) {
  172. item1.goodsNumsPrice.forEach(item2 => {
  173. if (item2.imgId === item.imgId) {
  174. // 商品图片
  175. item2.imgUrl = item.imgUrl;
  176. }
  177. });
  178. }
  179. });
  180. });
  181. }
  182. this.$refs.paging.complete(records);
  183. });
  184. },
  185. // 点击订单状态标签
  186. statusClick(e) {
  187. this.current = e.index;
  188. this.$refs.paging.reload();
  189. }
  190. }
  191. };
  192. </script>
  193. <style lang="scss"></style>