buySale.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <view class="content">
  3. <view class="nav-wrap flex">
  4. <view class="item" v-for="(nav,inden) in navList" :class="{'action': navCurrent == inden}"
  5. @click="changeNav(inden)">
  6. {{nav.tit}}
  7. </view>
  8. </view>
  9. <view class="order flex">
  10. <view class="" @click="navto('/pages/zero/order')">
  11. <image src="../../static/icon/order1.png" mode=""></image>挂售订单
  12. </view>
  13. <view class="" @click="navto('/pages/zero/orders')">
  14. <image src="../../static/icon/order1.png" mode="">买入订单
  15. </view>
  16. </view>
  17. <swiper :style="{'height':maxHeight}" class="scroll-wrap" :current="navCurrent">
  18. <swiper-item v-for="(item,index) in navList" >
  19. <scroll-view scroll-y="true" :style="{'height':maxHeight}">
  20. <view class="order-wrap " v-for="orderItem in item.list" >
  21. <view class="flex m-info">
  22. <image src="../../static/icon/gs-av.png" mode="" class="card-img"></image>
  23. <text style=" display: inline-block;line-height: 55rpx;" v-if="navCurrent == 0 && orderItem.user">{{orderItem.user.nickname}}</text>
  24. <text style=" display: inline-block;line-height: 55rpx;" v-if="navCurrent == 1 && orderItem.to_user">{{orderItem.to_user.nickname}}</text>
  25. </view>
  26. <view class="price">
  27. ¥{{orderItem.total_price}}
  28. </view>
  29. <view class="num">
  30. 数量:{{orderItem.amount}}
  31. </view>
  32. <view class="num">
  33. 单价:{{orderItem.price}}
  34. </view>
  35. <view class="num">
  36. {{ getTime(orderItem.add_time)}}
  37. </view>
  38. <view class="order-btn" @click="gobuy(orderItem)">
  39. {{navCurrent == 0? '立即购买':'立即抢单'}}
  40. </view>
  41. </view>
  42. <empty v-if="item.list.length==0 && item.loaded"></empty>
  43. <uni-load-more v-else :status="item.loadingType"></uni-load-more>
  44. </scroll-view>
  45. </swiper-item>
  46. </swiper>
  47. </view>
  48. </template>
  49. <script>
  50. import {
  51. mapState,
  52. mapMutations
  53. } from 'vuex';
  54. import empty from '@/components/empty.vue'
  55. import {
  56. getGsList,
  57. qxGs,
  58. upEvaluation,
  59. auth,
  60. buyGs,
  61. goBuy
  62. } from '@/api/zero.js'
  63. import {
  64. upload
  65. } from '@/api/order.js';
  66. export default {
  67. components: {
  68. empty
  69. },
  70. data() {
  71. return {
  72. pzing: false,
  73. orderId: '',
  74. pz: '',
  75. maxHeight: '',
  76. navCurrent: 0, // 0-》买单 1-》卖单
  77. current: 0, //二层次序
  78. navList: [{
  79. status: 0,
  80. tit: '我要买',
  81. list: [],
  82. out: 1,
  83. loadingType: 'more',
  84. page: 1,
  85. limit: 10,
  86. loaded: false
  87. },
  88. {
  89. out: 0,
  90. tit: '我要卖',
  91. list: [],
  92. loadingType: 'more',
  93. page: 1,
  94. limit: 10,
  95. status: 0,
  96. loaded: false
  97. },
  98. ]
  99. }
  100. },
  101. computed: {
  102. ...mapState('user', ['userInfo'])
  103. },
  104. onLoad() {
  105. },
  106. onShow() {
  107. this.getList('reload')
  108. },
  109. onReachBottom() {
  110. },
  111. onReady() {
  112. var that = this;
  113. uni.getSystemInfo({
  114. success: resu => {
  115. const query = uni.createSelectorQuery();
  116. query.select('.scroll-wrap').boundingClientRect();
  117. query.exec(function(res) {
  118. that.maxHeight = resu.windowHeight - res[0].top + 'px';
  119. });
  120. },
  121. fail: res => {}
  122. });
  123. },
  124. methods: {
  125. navto(url) {
  126. uni.navigateTo({
  127. url,
  128. fail() {
  129. uni.switchTab({
  130. url
  131. })
  132. }
  133. })
  134. },
  135. gobuy(item) {
  136. if(this.buying) {
  137. return
  138. }
  139. this.buying = true
  140. if(this.navCurrent == 0) {
  141. buyGs({
  142. id: item.id
  143. }).then(res => {
  144. uni.showToast({
  145. title:'购买成功',
  146. duration:2000
  147. });
  148. this.buying = false
  149. this.getList('reload')
  150. }).catch( err => {
  151. this.buying = false
  152. })
  153. }else {
  154. goBuy({
  155. id: item.id
  156. }).then(res => {
  157. uni.showToast({
  158. title:'提交成功',
  159. duration:2000
  160. });
  161. this.buying = false
  162. this.getList('reload')
  163. }).catch( err => {
  164. this.buying = false
  165. })
  166. }
  167. },
  168. showColor(status) {
  169. if (status == -1 || status == 4) {
  170. return '#aaa'
  171. } else {
  172. return '#FF5570'
  173. }
  174. },
  175. auth(item, type) {
  176. let that = this
  177. uni.showModal({
  178. title: '提示',
  179. content: type == 1 ? '是否确认收款完成?' : '是否确认当前提交的凭证没有通过审核',
  180. complete(e) {
  181. if (e.confirm) {
  182. auth({
  183. id: item.id,
  184. auth: type
  185. }).then(res => {
  186. uni.showToast({
  187. title: '审核成功',
  188. duration: 2000
  189. });
  190. that.getList('reload')
  191. })
  192. }
  193. }
  194. })
  195. },
  196. // 取消交易
  197. qxOrder(item) {
  198. let that = this
  199. uni.showModal({
  200. title: '提示',
  201. content: '是否确认取消挂售?',
  202. complete(e) {
  203. if (e.confirm) {
  204. qxGs({
  205. id: item.id
  206. }).then(res => {
  207. uni.showToast({
  208. title: '取消成功',
  209. duration: 2000
  210. });
  211. that.getList('reload')
  212. })
  213. }
  214. }
  215. })
  216. },
  217. upPz(item) {
  218. // if(item.up_files) {
  219. // this.pz = item.up_files
  220. // }
  221. // this.orderId = item.id
  222. // this.$refs.popup.open()
  223. uni.navigateTo({
  224. url: '/pages/zero/pay?id=' + item.id
  225. })
  226. },
  227. //上传凭证
  228. goUp() {
  229. if (this.pzing) {
  230. return
  231. }
  232. if (!this.pz) {
  233. return this.$api.msg('请上传凭证')
  234. }
  235. this.pzing = true
  236. upEvaluation({
  237. id: this.orderId,
  238. up_files: this.pz
  239. }).then(res => {
  240. uni.showToast({
  241. title: '上传成功',
  242. duration: 2000
  243. });
  244. this.$refs.popup.close()
  245. this.orderId = ''
  246. this.getList('reload')
  247. this.pzing = false
  248. }).catch(err => {
  249. this.pzing = false
  250. })
  251. },
  252. upimg() {
  253. upload({
  254. file: ''
  255. })
  256. .then(e => {
  257. console.log(e, 'e')
  258. this.pz = e[0].url
  259. console.log(this.pz)
  260. })
  261. .catch(e => {});
  262. },
  263. lookimg(item) {
  264. let arr = item.up_files.split(',')
  265. uni.previewImage({
  266. current: 0,
  267. loop: false,
  268. urls: arr,
  269. indicator: 'default'
  270. });
  271. },
  272. getTime(time) {
  273. const num = 13 - (time + '').length;
  274. let l = 1; //倍数
  275. for (let i = 0; i < num; i++) {
  276. l += '0';
  277. }
  278. // 重新解析为数字
  279. l = parseInt(l)
  280. const date = new Date(parseInt(time) * l);
  281. const year = date.getFullYear();
  282. const mon = date.getMonth() + 1;
  283. const day = date.getDate();
  284. const hours = date.getHours();
  285. const minu = date.getMinutes();
  286. const sec = date.getSeconds();
  287. return year + '-' + (mon > 9 ? mon : ('0' + mon)) + '-' + (day > 9 ? day : ('0' + day)) + ' ' + (hours > 9 ? hours : ('0' + hours)) + ':' + (minu > 9 ? minu : ('0' + minu)) + ':' + (sec > 9 ? sec : ('0' + sec));
  288. },
  289. // 切换nav
  290. changeNav(index) {
  291. if (index === this.navCurrent) {
  292. return
  293. }
  294. console.log('切换');
  295. this.navCurrent = index
  296. this.getList('tab')
  297. },
  298. changeNavT(index) {
  299. if (index === this.current) {
  300. return
  301. }
  302. console.log('切换');
  303. this.current = index
  304. this.getList('reload')
  305. },
  306. getList(type) {
  307. let that = this
  308. let item = that.navList[that.navCurrent]
  309. if (type == 'reload' || type == 'tab') {
  310. item.page = 1
  311. item.list = []
  312. item.loadingType = 'more'
  313. item.loaded = false
  314. }
  315. if (item.loadingType == 'loading' || item.loadingType == 'noMore') {
  316. return
  317. }
  318. item.loadingType = 'loading'
  319. let qdata = {
  320. page: item.page,
  321. limit: item.limit,
  322. status: item.status,
  323. order: 'id desc',
  324. out: item.out
  325. }
  326. getGsList(qdata).then(res => {
  327. let arr = res.data.result.list
  328. console.log(res.data.result.list,'res.data.result.list')
  329. item.list = item.list.concat(arr)
  330. console.log(item.list)
  331. if (item.limit == arr.length) {
  332. item.loadingType = 'more'
  333. item.page++
  334. } else {
  335. item.loadingType = 'noMore'
  336. }
  337. item.loaded = true
  338. })
  339. }
  340. }
  341. }
  342. </script>
  343. <style lang="scss" scoped>
  344. .nav-wrap {
  345. padding: 28rpx 30rpx 20rpx;
  346. background-color: #fff;
  347. .item {
  348. width: 336rpx;
  349. height: 81rpx;
  350. border-radius: 10rpx;
  351. border: 1px solid #EC5A54;
  352. color: #EC5A54;
  353. line-height: 80rpx;
  354. text-align: center;
  355. }
  356. .action {
  357. background-color: #EC5A54;
  358. color: #fff;
  359. }
  360. }
  361. .nav-list {
  362. justify-content: space-around;
  363. background-color: #fff;
  364. font-weight: 500;
  365. color: #333333;
  366. .item {
  367. padding: 28rpx 20rpx 16rpx;
  368. }
  369. .action {
  370. color: #EC5A54;
  371. border-bottom: 2px solid red;
  372. }
  373. }
  374. .scroll-wrap {
  375. padding-top: 20rpx;
  376. }
  377. .order-wrap {
  378. width: 686rpx;
  379. // height: 297rpx;
  380. background: #FFFFFF;
  381. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
  382. border-radius: 20rpx;
  383. margin: 0 auto 20rpx;
  384. padding: 33rpx 40rpx;
  385. position: relative;
  386. .m-info {
  387. justify-content: flex-start;
  388. image {
  389. width: 55rpx;
  390. height: 55rpx;
  391. margin-right: 13rpx;
  392. }
  393. text {
  394. font-size: 28rpx;
  395. font-weight: bold;
  396. color: #333333;
  397. }
  398. }
  399. .price {
  400. font-size: 40rpx;
  401. font-family: PingFang SC;
  402. font-weight: bold;
  403. color: #FF4C4C;
  404. padding: 40rpx 0 30rpx;
  405. }
  406. .num {
  407. font-size: 26rpx;
  408. font-weight: 500;
  409. color: #888785;
  410. }
  411. .status {
  412. position: absolute;
  413. right: 10rpx;
  414. top: 10rpx;
  415. font-size: 26rpx;
  416. }
  417. .btn-list {
  418. border-top: 1px solid #eee;
  419. margin-top: 20rpx;
  420. padding-top: 20rpx;
  421. justify-content: flex-end;
  422. }
  423. .order-btn {
  424. width: 148rpx;
  425. height: 62rpx;
  426. border: 2px solid #FF5570;
  427. border-radius: 30rpx;
  428. line-height: 62rpx;
  429. text-align: center;
  430. font-size: 28rpx;
  431. font-weight: bold;
  432. color: #FF4C4C;
  433. position: absolute;
  434. right: 40rpx;
  435. bottom: 33rpx;
  436. }
  437. .order-btn-hui {
  438. color: #aaa;
  439. border: 2px solid #aaa;
  440. }
  441. }
  442. .pz-wrap {
  443. width: 550rpx;
  444. // height: 500rpx;
  445. background-color: #fff;
  446. border-radius: 20rpx;
  447. text-align: center;
  448. font-size: 32rpx;
  449. padding: 40rpx;
  450. image {
  451. width: 250rpx;
  452. height: 250rpx;
  453. }
  454. .tit {
  455. font-weight: bold;
  456. padding: 20rpx 0;
  457. }
  458. .btn {
  459. background-color: $base-color;
  460. padding: 0 20rpx;
  461. height: 65rpx;
  462. border-radius: 25rpx;
  463. width: 250rpx;
  464. color: #fff;
  465. line-height: 60rpx;
  466. margin: 20rpx auto 0;
  467. }
  468. }
  469. .order {
  470. background-color: #fff;
  471. padding:30rpx;
  472. image {
  473. width: 30rpx;
  474. height: 33rpx;
  475. vertical-align: middle;
  476. margin-right: 10rpx;
  477. }
  478. }
  479. </style>