order.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div class="order">
  3. <div class="order-type">
  4. <van-tabs v-model="orderType" @change="switchType">
  5. <van-tab title="全部"></van-tab>
  6. <van-tab title="兑换中"></van-tab>
  7. <van-tab title="兑换成功"></van-tab>
  8. <van-tab title="兑换失败"></van-tab>
  9. </van-tabs>
  10. </div>
  11. <!-- <div class="order-date-time">
  12. <van-cell-group>
  13. <van-cell title="当前发货时间周期" :value="curDateTimeStr" is-link @click="choiceDateTime" />
  14. </van-cell-group>
  15. </div> -->
  16. <div class="order-content">
  17. <van-list v-model="loading" :finished="finished" finished-text="没有更多了..." :offset="10" @load="onLoad">
  18. <div class="order-item" v-for="(v,i) in orderList" :key="i" @click="navigateTo(v.id)">
  19. <div class="order-institution">
  20. <div class="order-header ellipsis">{{v.addDataTime}}</div>
  21. <div class="order-institution-name order-info ellipsis">{{v.organizationName}}</div>
  22. </div>
  23. <div class="order-product">
  24. <div class="order-header ellipsis">产品名称</div>
  25. <div class="order-product-name order-info ellipsis">{{v.productName}}</div>
  26. </div>
  27. <div class="order-money">
  28. <div class="order-header ellipsis">兑换金额</div>
  29. <div class="order-exchange-money order-info ellipsis">¥{{v.exchangePrice/100}}</div>
  30. </div>
  31. <div class="order-status">
  32. <van-icon :name="v.state=='success'?'checked':v.state=='failed'?'clear':'clock-o'" :color="v.state=='success'?'#1989fa':v.state=='failed'?'#f44':''" size="20px" />
  33. </div>
  34. </div>
  35. </van-list>
  36. </div>
  37. <!-- 时间日期选择组件 -->
  38. <van-popup v-model="showDateTime" position="bottom">
  39. <van-datetime-picker v-model="curDateTime" type="date" @confirm="confirmDateTime" @cancel="cancelDateTime" />
  40. </van-popup>
  41. </div>
  42. </template>
  43. <script>
  44. import {
  45. Tab,
  46. Tabs,
  47. List,
  48. Cell,
  49. CellGroup,
  50. Icon,
  51. Dialog,
  52. Popup,
  53. DatetimePicker
  54. } from "vant";
  55. import api from "@/util/api";
  56. import Util from "@/util/utils";
  57. export default {
  58. name: "orderList",
  59. components: {
  60. [Tab.name]: Tab,
  61. [Tabs.name]: Tabs,
  62. [Icon.name]: Icon,
  63. [List.name]: List,
  64. [Cell.name]: Cell,
  65. [Popup.name]: Popup,
  66. [Dialog.name]: Dialog,
  67. [CellGroup.name]: CellGroup,
  68. [DatetimePicker.name]: DatetimePicker
  69. },
  70. data() {
  71. return {
  72. orderType: 0,
  73. orderStatus: null,
  74. currentPage: 0,
  75. pageSize: 20,
  76. totalPage: 1,
  77. orderList: [],
  78. curDateTimeStr: "",
  79. showDateTime: !1,
  80. curDateTime: null,
  81. loading: !1,
  82. finished: !1
  83. };
  84. },
  85. computed: {},
  86. created() {
  87. const _orderType = this.$route.query.orderType;
  88. this.orderType = _orderType;
  89. switch (_orderType) {
  90. case 1:
  91. this.orderStatus = "waiting";
  92. break;
  93. case 2:
  94. this.orderStatus = "success";
  95. break;
  96. case 3:
  97. this.orderStatus = "failed";
  98. break;
  99. default:
  100. this.orderStatus = null;
  101. }
  102. },
  103. mounted() {
  104. this.setCurDateTime();
  105. },
  106. methods: {
  107. //init
  108. init() {
  109. this.orderList = [];
  110. this.currentPage = 0;
  111. this.totalPage = 1;
  112. this.loading = !1;
  113. this.finished = !1;
  114. },
  115. //跳转详情
  116. navigateTo(_id) {
  117. this.$router.push({ name: "orderDetail", query: { id: _id } });
  118. },
  119. //切换订单分类状态
  120. switchType(e) {
  121. const _index = e;
  122. this.orderType = _index;
  123. switch (_index) {
  124. case 1:
  125. this.orderStatus = "waiting";
  126. break;
  127. case 2:
  128. this.orderStatus = "success";
  129. break;
  130. case 3:
  131. this.orderStatus = "failed";
  132. break;
  133. default:
  134. this.orderStatus = null;
  135. }
  136. this.init();
  137. this.onLoad();
  138. },
  139. //初始化当前时间
  140. setCurDateTime() {
  141. const date = new Date();
  142. const year = date.getFullYear();
  143. const month = date.getMonth() + 1;
  144. const day = date.getDate();
  145. const dateTime = [year, month, day].map(Util.formatNumber).join("-");
  146. this.curDateTimeStr = dateTime;
  147. this.curDateTime = date;
  148. },
  149. //选择订单周期时间
  150. choiceDateTime() {
  151. this.showDateTime = !0;
  152. },
  153. //确认时间
  154. confirmDateTime(e) {
  155. const dateTimeStr = Util.formatTime(e);
  156. this.curDateTimeStr = dateTimeStr;
  157. this.showDateTime = !1;
  158. this.init();
  159. this.onLoad();
  160. },
  161. //取消时间
  162. cancelDateTime() {
  163. this.showDateTime = !1;
  164. },
  165. //获取商品列表
  166. async getOrderList() {
  167. const _order = await api
  168. .getOrderList({
  169. currentPage: this.currentPage,
  170. pageSize: this.pageSize,
  171. where: {
  172. // time: this.curDateTimeStr,
  173. state: this.orderStatus
  174. }
  175. })
  176. .then(res => {
  177. if (res.code == 0) {
  178. let data = res.result,
  179. _list = data.list,
  180. list = this.orderList;
  181. this.loading = !1;
  182. this.totalPage = data.totalPage;
  183. // this.curDateTimeStr = data.curDataTime;
  184. if (_list.length > 0) {
  185. this.finished = !1;
  186. this.orderList = list.concat(_list);
  187. } else {
  188. this.finished = !0;
  189. }
  190. }
  191. })
  192. .catch(err => {});
  193. },
  194. // 上拉加载更多
  195. async onLoad() {
  196. this.currentPage += 1;
  197. if (this.currentPage > this.totalPage) {
  198. this.finished = !0;
  199. this.loading = !1;
  200. } else {
  201. await this.getOrderList();
  202. }
  203. }
  204. }
  205. };
  206. </script>
  207. <style lang="less">
  208. @import "../../style/common";
  209. .order {
  210. position: relative;
  211. &-type {
  212. position: fixed;
  213. top: 0;
  214. left: 0;
  215. right: 0;
  216. height: 44px;
  217. z-index: 99;
  218. }
  219. &-date-time {
  220. position: fixed;
  221. top: 44px;
  222. left: 0;
  223. right: 0;
  224. height: 44px;
  225. z-index: 99;
  226. }
  227. &-content {
  228. padding-top: 44px;
  229. .order-item {
  230. position: relative;
  231. display: flex;
  232. align-items: center;
  233. justify-content: space-between;
  234. padding: 10px;
  235. text-align: center;
  236. background: #fff;
  237. .order-institution {
  238. width: 30%;
  239. padding: 0 5px;
  240. }
  241. .order-product {
  242. width: 35%;
  243. padding: 0 5px;
  244. }
  245. .order-money {
  246. width: 25%;
  247. padding: 0 5px;
  248. }
  249. .order-status {
  250. width: 10%;
  251. padding: 0 5px;
  252. text-align: left;
  253. }
  254. .order-header {
  255. padding-bottom: 5px;
  256. font-size: 12px;
  257. color: #999;
  258. }
  259. .order-info {
  260. color: #333;
  261. }
  262. }
  263. .order-item::before {
  264. .backgroundLine();
  265. }
  266. .order-item::after {
  267. font: normal normal normal 14px/1 "vant-icon";
  268. position: absolute;
  269. content: "\F00A";
  270. width: 14px;
  271. height: 14px;
  272. right: 5px;
  273. top: 50%;
  274. transform: translateY(-50%);
  275. overflow: hidden;
  276. }
  277. }
  278. }
  279. </style>