buySale.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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' + mun)) + '-' + (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. item.list = item.list.concat(arr)
  329. console.log(item.list)
  330. if (item.limit == arr.length) {
  331. item.loadingType = 'more'
  332. item.page++
  333. } else {
  334. item.loadingType = 'noMore'
  335. }
  336. item.loaded = true
  337. })
  338. }
  339. }
  340. }
  341. </script>
  342. <style lang="scss" scoped>
  343. .nav-wrap {
  344. padding: 28rpx 30rpx 20rpx;
  345. background-color: #fff;
  346. .item {
  347. width: 336rpx;
  348. height: 81rpx;
  349. border-radius: 10rpx;
  350. border: 1px solid #EC5A54;
  351. color: #EC5A54;
  352. line-height: 80rpx;
  353. text-align: center;
  354. }
  355. .action {
  356. background-color: #EC5A54;
  357. color: #fff;
  358. }
  359. }
  360. .nav-list {
  361. justify-content: space-around;
  362. background-color: #fff;
  363. font-weight: 500;
  364. color: #333333;
  365. .item {
  366. padding: 28rpx 20rpx 16rpx;
  367. }
  368. .action {
  369. color: #EC5A54;
  370. border-bottom: 2px solid red;
  371. }
  372. }
  373. .scroll-wrap {
  374. padding-top: 20rpx;
  375. }
  376. .order-wrap {
  377. width: 686rpx;
  378. // height: 297rpx;
  379. background: #FFFFFF;
  380. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
  381. border-radius: 20rpx;
  382. margin: 0 auto 20rpx;
  383. padding: 33rpx 40rpx;
  384. position: relative;
  385. .m-info {
  386. justify-content: flex-start;
  387. image {
  388. width: 55rpx;
  389. height: 55rpx;
  390. margin-right: 13rpx;
  391. }
  392. text {
  393. font-size: 28rpx;
  394. font-weight: bold;
  395. color: #333333;
  396. }
  397. }
  398. .price {
  399. font-size: 40rpx;
  400. font-family: PingFang SC;
  401. font-weight: bold;
  402. color: #FF4C4C;
  403. padding: 40rpx 0 30rpx;
  404. }
  405. .num {
  406. font-size: 26rpx;
  407. font-weight: 500;
  408. color: #888785;
  409. }
  410. .status {
  411. position: absolute;
  412. right: 10rpx;
  413. top: 10rpx;
  414. font-size: 26rpx;
  415. }
  416. .btn-list {
  417. border-top: 1px solid #eee;
  418. margin-top: 20rpx;
  419. padding-top: 20rpx;
  420. justify-content: flex-end;
  421. }
  422. .order-btn {
  423. width: 148rpx;
  424. height: 62rpx;
  425. border: 2px solid #FF5570;
  426. border-radius: 30rpx;
  427. line-height: 62rpx;
  428. text-align: center;
  429. font-size: 28rpx;
  430. font-weight: bold;
  431. color: #FF4C4C;
  432. position: absolute;
  433. right: 40rpx;
  434. bottom: 33rpx;
  435. }
  436. .order-btn-hui {
  437. color: #aaa;
  438. border: 2px solid #aaa;
  439. }
  440. }
  441. .pz-wrap {
  442. width: 550rpx;
  443. // height: 500rpx;
  444. background-color: #fff;
  445. border-radius: 20rpx;
  446. text-align: center;
  447. font-size: 32rpx;
  448. padding: 40rpx;
  449. image {
  450. width: 250rpx;
  451. height: 250rpx;
  452. }
  453. .tit {
  454. font-weight: bold;
  455. padding: 20rpx 0;
  456. }
  457. .btn {
  458. background-color: $base-color;
  459. padding: 0 20rpx;
  460. height: 65rpx;
  461. border-radius: 25rpx;
  462. width: 250rpx;
  463. color: #fff;
  464. line-height: 60rpx;
  465. margin: 20rpx auto 0;
  466. }
  467. }
  468. .order {
  469. background-color: #fff;
  470. padding:30rpx;
  471. image {
  472. width: 30rpx;
  473. height: 33rpx;
  474. vertical-align: middle;
  475. margin-right: 10rpx;
  476. }
  477. }
  478. </style>