index.vue 7.0 KB

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