index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view class="order">
  3. <!-- header -->
  4. <cu-custom bgColor="bg-gradual-blue" isBack><view slot="content">拼团订单</view></cu-custom>
  5. <!-- section -->
  6. <cu-nav :active="active" @onChange="onChange" :value="value" />
  7. <view v-for="(item, index) in value" :key="index" class="box">
  8. <view v-show="index == active">
  9. <view style="overflow: hidden;" v-for="(itemB, indexB) of item.value" :key="indexB" class="bg-white padding-top-sm radius margin-lr margin-top">
  10. <view class="padding-sm">
  11. <view class="padding-bottom-sm text-black text-bold ">{{ itemB.activity_name }}</view>
  12. <view v-if="itemB.show_amount && itemB.order_status" class="flex justify-between">
  13. <view class="padding-bottom-sm text-sm text-black">金额: {{ itemB.show_amount }}元</view>
  14. <view class="padding-bottom-sm text-sm text-black">状态: {{ itemB.order_status }}</view>
  15. </view>
  16. <view class="padding-bottom-sm text-sm text-black" v-if="itemB.show_amount && !itemB.order_status">金额: {{ itemB.show_amount }}元</view>
  17. <view class="padding-bottom-sm text-sm text-black" v-if="itemB.order_status && !itemB.show_amount">状态: {{ itemB.order_status }}</view>
  18. <view class="padding-bottom-sm text-sm text-black" v-if="itemB.name">{{ itemB.name }}:{{ itemB.tel }}</view>
  19. <view class="padding-bottom-sm text-sm text-black" v-else>电话:{{ itemB.tel }}</view>
  20. <view class="padding-bottom-sm text-sm text-black" v-if="itemB.number">车牌号: {{ itemB.number }}</view>
  21. <view class="padding-bottom-sm text-sm text-black" v-if="itemB.model">车型: {{ itemB.model }}</view>
  22. <view class="padding-bottom-sm text-sm text-black" v-if="itemB.create_time">创建时间: {{ itemB.create_time }}</view>
  23. </view>
  24. <view v-if="active == '0'" class="flex">
  25. <view style="flex: 1;" @click="onPay(itemB.id, indexB)" class="padding text-center bg-green">支付</view>
  26. <view style="flex: 1;" @click="onClick(itemB.id, indexB)" class="padding text-center bg-red">删除</view>
  27. </view>
  28. <view v-else @click="onClick(itemB.id, indexB)" class="padding text-center bg-red">删除</view>
  29. </view>
  30. <van-empty v-if="item.value.length == 0 && item.no_more" description="暂无订单" />
  31. <view v-else :class="!item.no_more && item.pageCount <= item.totalPage ? 'cu-load bg-grey loading margin-top' : 'cu-load bg-grey over margin-top'"></view>
  32. </view>
  33. </view>
  34. <!-- footer -->
  35. <!-- 微信快捷登录 -->
  36. <van-dialog id="van-dialog" />
  37. </view>
  38. </template>
  39. <script>
  40. import Dialog from '@/wxcomponents/vant/dist/dialog/dialog';
  41. export default {
  42. data() {
  43. return {
  44. active: 0,
  45. value: [
  46. {
  47. id: 1,
  48. name: '进行中',
  49. no_more: false, //没有更多
  50. pageCount: 1,
  51. totalPage: 1,
  52. value: []
  53. },
  54. {
  55. id: 2,
  56. name: '拼团成功',
  57. no_more: false, //没有更多
  58. pageCount: 1,
  59. totalPage: 1,
  60. value: []
  61. },
  62. {
  63. id: 3,
  64. name: '拼团失败',
  65. no_more: false, //没有更多
  66. pageCount: 1,
  67. totalPage: 1,
  68. value: []
  69. }
  70. ]
  71. };
  72. },
  73. onLoad(options) {
  74. this.active = options.active || 0;
  75. this.request();
  76. },
  77. methods: {
  78. // 报错
  79. showErr(content) {
  80. content = JSON.stringify(content) === '{}' ? '未知错误' : content;
  81. uni.showModal({
  82. content,
  83. showCancel: false,
  84. success: res => console.log(res)
  85. });
  86. },
  87. // 支付
  88. async onPay(id, index) {
  89. try {
  90. var res = await this.$global.request({
  91. url: `/customer/order/${id}/pay_order/ `,
  92. method: 'post',
  93. header: {
  94. 'Content-Type': 'application/x-www-form-urlencoded',
  95. Authorization: uni.getStorageSync('token')
  96. },
  97. data: {
  98. openid: this.$store.state.userInfo.openid,
  99. appid: this.$store.state.userInfo.appid,
  100. activity_id: this.$store.state.userInfo.activity_id
  101. }
  102. });
  103. this.signature(res.data, index);
  104. } catch (err) {
  105. this.showErr(err);
  106. }
  107. },
  108. // 支付签名
  109. signature(data, index) {
  110. uni.requestPayment({
  111. timeStamp: data.timeStamp,
  112. nonceStr: data.nonceStr,
  113. package: data.package,
  114. signType: data.signType,
  115. paySign: data.paySign,
  116. success: () => {
  117. var value = JSON.parse(JSON.stringify(this.value));
  118. var no_a = value[this.active].value.splice(index, 1);
  119. value[1].value.unshift(no_a[0]);
  120. this.value = value;
  121. uni.showToast({
  122. icon: 'none',
  123. title: '支付成功'
  124. });
  125. },
  126. fail: () => {
  127. uni.showToast({
  128. icon: 'none',
  129. title: '支付失败'
  130. });
  131. }
  132. });
  133. },
  134. // 删除
  135. onClick(id, index) {
  136. Dialog.confirm({
  137. title: '提示',
  138. message: '确定要删除该订单?',
  139. })
  140. .then(() => {
  141. this.deleteIndex(id,index)
  142. })
  143. .catch(() => {
  144. // on cancel
  145. });
  146. },
  147. async deleteIndex(id, index) {
  148. try {
  149. var res = await this.$global.request({
  150. url: `/customer/order/${id}/del_order/ `,
  151. method: 'post',
  152. header: {
  153. 'Content-Type': 'application/x-www-form-urlencoded',
  154. Authorization: uni.getStorageSync('token')
  155. },
  156. data: {
  157. appid: this.$store.state.userInfo.appid,
  158. activity_id: this.$store.state.userInfo.activity_id
  159. }
  160. });
  161. var value = JSON.parse(JSON.stringify(this.value));
  162. value[this.active].value.splice(index, 1);
  163. this.value = value;
  164. } catch (err) {
  165. this.showErr(err);
  166. }
  167. },
  168. // 不同状态
  169. onChange(index) {
  170. this.active = index;
  171. this.request();
  172. },
  173. // 请求
  174. async request() {
  175. var $value = JSON.parse(JSON.stringify(this.value));
  176. var { name, pageCount, no_more, totalPage, value, id } = $value[this.active];
  177. if (pageCount > totalPage) return false;
  178. var res = await this.$global.request({
  179. url: '/customer/order/',
  180. header: {
  181. 'Content-Type': 'application/x-www-form-urlencoded',
  182. Authorization: uni.getStorageSync('token')
  183. },
  184. method: 'get',
  185. data: {
  186. page: pageCount,
  187. limit: 20,
  188. order_status: id,
  189. appid: this.$store.state.userInfo.appid,
  190. activity_id: this.$store.state.userInfo.activity_id
  191. }
  192. });
  193. pageCount++;
  194. totalPage = res.totalPage;
  195. if (pageCount > totalPage) no_more = true;
  196. value = value.concat(res.data);
  197. $value[this.active] = { name, pageCount, no_more, totalPage, value, id };
  198. this.value = $value;
  199. }
  200. }
  201. };
  202. </script>
  203. <style></style>