index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <page title="订单详情" ref="pageRef" nav-color="transparent">
  3. <view v-if="data" class="wrapper marginT12 marginX16 padding16 bgcolor-white radius12">
  4. <view class="flex-align paddingY16">
  5. <view class="bold">订单详情</view>
  6. <view v-if="data.type == 2" class="presell">预售订单</view>
  7. </view>
  8. <view class="top flex-align flex1">
  9. <image :src="data.itemList[0].cover" mode="scaleToFill" class="img radius8" />
  10. <view class="self-stretch flex-column-between marginL12 flex1">
  11. <view class="color-1 font4">{{ data.itemList[0].name }}</view>
  12. <view class="flex-align-between">
  13. <view class="color-theme">
  14. <text class="font2">¥</text>
  15. <text class="font8 bold">{{ data.itemList[0].price }}</text>
  16. </view>
  17. <view class="color-1 font2">x{{ data.itemList[0].quantity }}</view>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="flex-align-between font2">
  22. <view>商品金额</view>
  23. <view>¥{{ data.totalAmount }}</view>
  24. </view>
  25. <view class="flex-align-between font2 paddingT12">
  26. <view>快递费</view>
  27. <view>¥{{ data.expressAmount }}</view>
  28. </view>
  29. <view class="flex-align-between font2 paddingT12">
  30. <view>优惠券</view>
  31. <view>-¥{{ data.couponAmount }}</view>
  32. </view>
  33. <view
  34. v-if="data.status === 0 && data.type == 2 && data.paidAmount > 0"
  35. class="paddingT25 flex-align-end"
  36. >
  37. <view class="font2 color-3">共{{ data.itemList[0].quantity }}件</view>
  38. <view class="flex-align paddingL12">
  39. <view class="color-3 font1 flex-align">
  40. <view>总价:</view>
  41. <view class="">
  42. <text class="font1">¥</text>
  43. <text class="font6 bold">{{ data.totalAmount }}</text>
  44. </view>
  45. </view>
  46. <view class="color-theme font1 flex-align paddingL12">
  47. <view>需付款:</view>
  48. <view class="">
  49. <text class="font1">¥</text>
  50. <text class="font6 bold">
  51. {{ data.paymentAmount - data.paidAmount }}
  52. </text>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view v-else-if="data.status === 0" class="paddingT25 flex-align-end">
  58. <view class="font2 color-3">共{{ data.itemList[0].quantity }}件</view>
  59. <view class="color-1 paddingL9">小计:</view>
  60. <view class="color-theme font8 paddingL4">
  61. <text class="font4">¥</text>
  62. {{ data.paymentAmount }}
  63. </view>
  64. </view>
  65. <view v-else class="paddingT25 flex-align-end">
  66. <view class="font2 color-3">共{{ data.itemList[0].quantity }}件</view>
  67. <view class="font2 color-1 paddingL9">实付款:</view>
  68. <view class="color-1 font8 paddingL4">
  69. <text class="font4">¥</text>
  70. {{ data.paidAmount }}
  71. </view>
  72. </view>
  73. </view>
  74. <view v-if="data" class="marginT12 marginX16 padding16 bgcolor-white radius12">
  75. <view class="flex-align-between">
  76. <view class="font2 flex-shrink0">订单号</view>
  77. <view class="font2 flex1 text-right line-ellipsis marginL10">
  78. {{ data.tradeNo }}
  79. </view>
  80. <button class="btn-clear copy marginL5 flex-shrink0" @click="copy(data.tradeNo)">
  81. 复制
  82. </button>
  83. </view>
  84. <view class="flex-align-between paddingT20">
  85. <view class="font2 flex-shrink0">下单时间</view>
  86. <view class="font2">{{ data.createTime }}</view>
  87. </view>
  88. <view class="flex-align-between paddingT20" v-if="data.paymentTime">
  89. <view class="font2 flex-shrink0">付款时间</view>
  90. <view class="font2">{{ data.paymentTime }}</view>
  91. </view>
  92. <view class="flex-align-between paddingT20">
  93. <view class="font2 flex-shrink0">收货地址</view>
  94. <view class="font2 text-right marginL16">
  95. {{ data.contactName }},{{ data.contactNo }},{{ data.province }}{{ data.city
  96. }}{{ data.district }}{{ data.address }}
  97. </view>
  98. </view>
  99. </view>
  100. <view
  101. v-if="data && data.type === 2"
  102. class="flex-align-between marginT12 marginX16 padding16 bgcolor-white radius12"
  103. >
  104. <view class="font2 flex-shrink0">尾款提醒手机号</view>
  105. <view class="font2 text-right marginL10">
  106. {{ data.restNotifyMobile }}
  107. </view>
  108. </view>
  109. <view class="fill"></view>
  110. <view v-if="data" class="bottom-fixed bgcolor-white">
  111. <view
  112. v-if="[0, 1].includes(data.status)"
  113. :class="data.status === 1 ? 'paddingB25' : null"
  114. class="paddingX16 paddingT13 flex-align-end"
  115. >
  116. <button
  117. :class="data.status === 1 ? 'btn-size' : 'btn'"
  118. class="cm-plain-btn"
  119. style="margin-right: 20rpx !important"
  120. @click.stop="showAddress"
  121. >
  122. 修改地址
  123. </button>
  124. <button
  125. v-if="data.type === 2 && data.status === 0"
  126. :class="data.status === 1 ? 'btn-size' : 'btn'"
  127. class="cm-plain-btn"
  128. @click.stop="showModal = true"
  129. >
  130. 修改尾款手机号
  131. </button>
  132. </view>
  133. <view v-if="data.status === 0" class="paddingX16 paddingT13 paddingB25 flex-align-end">
  134. <view class="flex-align">
  135. <view
  136. v-if="data.type === 1 || (data.type === 2 && data.restFlag === 1)"
  137. class="color-1"
  138. >
  139. 合计:
  140. </view>
  141. <view v-if="data.type === 2 && !data.restFlag" class="color-1">需付定金:</view>
  142. <view
  143. v-if="data.type === 1 || (data.type === 2 && data.restFlag === 1)"
  144. class="color-theme font8 paddingL4 paddingR16"
  145. >
  146. <text class="font4">¥</text>
  147. {{ data.paymentAmount - data.paidAmount }}
  148. </view>
  149. <text
  150. v-if="data.type === 2 && !data.restFlag"
  151. class="color-theme font8 paddingL4 paddingR16"
  152. >
  153. ¥{{ data.depositAmount }}
  154. </text>
  155. </view>
  156. <button class="cm-btn btn-size" @click.stop="realPay">确认并支付</button>
  157. </view>
  158. <view
  159. v-if="[2, 99].includes(data.status)"
  160. class="paddingX16 paddingT13 paddingB25 flex-align-end"
  161. >
  162. <button class="cm-plain-btn btn-size" @click="showExpress">查看物流</button>
  163. <view v-if="data.status === 2" class="paddingL16 flex-shrink0">
  164. <button class="cm-plain-btn btn-size" @click.stop="receive">确认收货</button>
  165. </view>
  166. </view>
  167. </view>
  168. <view v-if="showModal" class="modal">
  169. <view class="phone-modal flex-column-align-center">
  170. <view class="title">修改尾款提醒手机号</view>
  171. <view class="content flex-align">
  172. <text class="">手机号:</text>
  173. <input
  174. class="phone"
  175. style="width: 400rpx"
  176. v-model.trim="phoneNum"
  177. type="number"
  178. placeholder-style="color: #ccc"
  179. />
  180. </view>
  181. <view class="flex-align footer">
  182. <button class="btn" @click.stop="showModal = false">取消</button>
  183. <button class="btn marginL10" @click.stop="showPhone">确定</button>
  184. </view>
  185. </view>
  186. </view>
  187. </page>
  188. </template>
  189. <script>
  190. import resource from '@/utils/resource'
  191. import { baseEncode } from '../../utils/utils'
  192. export default {
  193. data() {
  194. return {
  195. resource,
  196. data: null,
  197. tradeNo: '',
  198. showModal: false,
  199. phoneNum: ''
  200. }
  201. },
  202. computed:{
  203. payInfo() {
  204. return this.$store.state.payInfo
  205. }
  206. },
  207. watch: {
  208. payInfo(val) {
  209. if (val && val.payResult == 'SUCCESS') {
  210. this.paySuccess(val)
  211. } else if (val && val.payResult !== 'SUCCESS') {
  212. }
  213. }
  214. },
  215. onLoad(options) {
  216. this.tradeNo = options.tradeNo
  217. },
  218. mounted() {
  219. setTimeout(() => {
  220. this.getData(true)
  221. }, 100)
  222. },
  223. onPullDownRefresh() {
  224. this.getData(false)
  225. },
  226. onShow() {
  227. this.getData(true)
  228. },
  229. methods: {
  230. async getData(loading = false) {
  231. const res = await this.$service.mall.orderDetail(this.tradeNo, loading)
  232. uni.stopPullDownRefresh()
  233. if (res && res.itemList[0].spu) {
  234. let obj = res.itemList[0].spu
  235. if (obj.parameter) {
  236. res.itemList[0].parameterStr = JSON.parse(obj.parameter)
  237. .map((item) => item.value)
  238. .join('/')
  239. }
  240. }
  241. this.data = res
  242. },
  243. copy(text) {
  244. this.$common.copy(text)
  245. },
  246. showAddress() {
  247. this.$router.push('address', { type: 0, tradeNo: this.tradeNo })
  248. },
  249. async showPhone() {
  250. if (this.phoneNum) {
  251. await this.$service.mall
  252. .updatePhone({
  253. restNotifyMobile: this.phoneNum,
  254. tradeNo: this.data.tradeNo
  255. })
  256. .then((res) => {
  257. if (res.code === '0') {
  258. this.$message.success('修改成功!')
  259. this.showModal = false
  260. this.getData(true)
  261. }
  262. })
  263. } else {
  264. this.$message.warn('尾款提醒手机号不能为空!')
  265. }
  266. },
  267. showExpress() {
  268. this.$router.push('packages', { type: 1, tradeNo: this.data.deliveryTradeNo })
  269. },
  270. async realPay() {
  271. const res = await this.$service.mall.orderPay(this.tradeNo, 'WXPAY_JSAPI')
  272. if (res) {
  273. if (res.paySuccess) {
  274. this.getData(true)
  275. if (this.$store.state.hide == 1) {
  276. this.$service.user.getHide()
  277. }
  278. return
  279. }
  280. let self = this
  281. // 支付宝支付
  282. uni.requestPayment({
  283. provider: 'alipay',
  284. orderInfo: res.payInfo,
  285. success: function (res) {
  286. self.close()
  287. if (self.$store.state.hide == 1) {
  288. self.$service.user.getHide()
  289. }
  290. self.$router.push('order_product')
  291. },
  292. fail: function (err) {
  293. console.log('fail:' + JSON.stringify(err));
  294. }
  295. });
  296. return
  297. }
  298. },
  299. wechatPay(data) {
  300. let payInfo = data.payInfo
  301. wx.requestPayment({
  302. timeStamp: payInfo.timeStamp,
  303. nonceStr: payInfo.nonceStr,
  304. package: payInfo.packageValue,
  305. signType: payInfo.signType,
  306. paySign: payInfo.paySign,
  307. success: (res) => {
  308. this.close()
  309. if (this.$store.state.hide == 1) {
  310. this.$service.user.getHide()
  311. }
  312. this.$router.push('order_product')
  313. },
  314. fail: (res) => {}
  315. })
  316. },
  317. thirdPay(data) {
  318. let self = this
  319. let redirectUrl = data.redirectUrl
  320. let requestId = data.requestId
  321. const base64Url = encodeURIComponent(baseEncode(redirectUrl))
  322. wx.openEmbeddedMiniProgram({
  323. path: 'pages/pay/order', // 启动目标页面
  324. appId: 'wx0448557563ffc600', // 启动的小程序
  325. envVersion: 'release', // develop | trial | release
  326. verify: 'binding',
  327. extraData: {
  328. title: '订单付款', // 导航Title
  329. tip: `待支付订单付款`, // 支付提示内容
  330. requestId: requestId, // 本次请求ID
  331. action: 'epPay', // 支付模式
  332. payUrl: base64Url // 支付地址, 需要进行Base64转换
  333. },
  334. success: (res) => {
  335. console.info('启动成功', res)
  336. },
  337. fail: (err) => {
  338. console.info('启动失败', err)
  339. }
  340. })
  341. },
  342. paySuccess(payInfo) {
  343. this.close()
  344. this.$store.state.payInfo = null
  345. if (this.$store.state.hide == 1) {
  346. this.$service.user.getHide()
  347. }
  348. this.$router.push('order_product')
  349. },
  350. receive() {
  351. this.$message.confirm('确认收货吗?', async () => {
  352. const res = await this.$service.mall.receive(this.tradeNo)
  353. res && this.getData(true)
  354. })
  355. }
  356. }
  357. }
  358. </script>
  359. <style lang="scss" scoped>
  360. .wrapper {
  361. padding: 0 20rpx !important;
  362. .presell {
  363. height: 44rpx;
  364. line-height: 44rpx;
  365. border-radius: 22rpx;
  366. font-size: 24rpx;
  367. color: #fff;
  368. padding: 0 16rpx;
  369. background: $color-theme;
  370. margin-left: 16rpx;
  371. }
  372. .top {
  373. padding: 0 0 40rpx;
  374. .img {
  375. width: 136rpx;
  376. height: 136rpx;
  377. }
  378. }
  379. }
  380. .copy {
  381. padding: 0 6rpx;
  382. line-height: 32rpx;
  383. border-radius: 8rpx;
  384. text-align: center;
  385. color: #000;
  386. font-size: 24rpx;
  387. background: #fec433;
  388. }
  389. .fill {
  390. height: 172rpx;
  391. }
  392. .btn-size {
  393. width: 288rpx;
  394. height: 64rpx;
  395. border-radius: 44rpx;
  396. font-size: 28rpx;
  397. }
  398. .btn {
  399. height: 48rpx;
  400. line-height: 48rpx;
  401. text-align: center;
  402. padding: 0 20rpx;
  403. color: #fff;
  404. font-size: 28rpx;
  405. background: linear-gradient(90deg, #2affff 0%, #4d70f2 100%);
  406. border-radius: 24rpx;
  407. }
  408. .modal {
  409. position: fixed;
  410. top: 0;
  411. left: 0;
  412. right: 0;
  413. bottom: 0;
  414. background-color: rgba(0, 0, 0, 0.5);
  415. display: flex;
  416. justify-content: center;
  417. align-items: center;
  418. .phone-modal {
  419. position: relative;
  420. width: 600rpx;
  421. height: 400rpx;
  422. background-color: white;
  423. padding: 20px;
  424. border-radius: 5px;
  425. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  426. .title {
  427. width: 350rpx;
  428. position: absolute;
  429. top: 30rpx;
  430. left: 50%;
  431. transform: translateX(-50%);
  432. font-size: 40rpx;
  433. font-weight: 500;
  434. }
  435. .content {
  436. .phone {
  437. color: #000;
  438. height: 78rpx;
  439. background: rgb(241, 239, 239);
  440. border-radius: 16rpx;
  441. margin: 0 auto;
  442. }
  443. }
  444. .footer {
  445. position: absolute;
  446. bottom: 40rpx;
  447. right: 40rpx;
  448. }
  449. }
  450. }
  451. </style>