pay.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <view>
  3. <Loading :type="3" :loadStatus="loadStatus" :showText="errorText" />
  4. <zj-page-layout :hasFooter="true" v-if="detail">
  5. <view style="padding: 1rpx 30rpx">
  6. <view class="materials-container card mt30">
  7. <view class="title">
  8. <view class="t1">支付金额</view>
  9. <view class="t2"
  10. >¥<text>{{ detail.totalAmount | priceFilter }}</text></view
  11. >
  12. </view>
  13. <view class="id"><text>订单号:</text>{{ detail.orderId }}</view>
  14. <view class="product">
  15. <view
  16. class="it"
  17. v-for="(item, index) in wbId ? detail.rpMaterialOrderItems : detail.workerOrderItems"
  18. :key="index"
  19. >
  20. <view class="name"
  21. >{{ item.goodsName }}<text>×{{ item.num }}{{ item.unit }}</text></view
  22. >
  23. <view class="price">¥{{ item.totalAmount | priceFilter }}</view>
  24. </view>
  25. <view class="total">
  26. <view class="text">合计:</view>
  27. <view class="price">¥{{ detail.totalAmount | priceFilter }}</view>
  28. </view>
  29. </view>
  30. <view class="row"><text>备注:</text>{{ detail.remark }}</view>
  31. <view class="row"><text>操作人:</text>{{ detail.workerName }}</view>
  32. </view>
  33. </view>
  34. <template slot="footer">
  35. <view class="footer-btn-group">
  36. <u-button text="取消订单" @click="cancelOrder"></u-button>
  37. <u-button text="扫码支付" type="primary" @click="scanCode"></u-button>
  38. </view>
  39. </template>
  40. </zj-page-layout>
  41. <zhifutanchuan v-if="state > 0" :detail="detail" :orderId="orderId" :state="state" @scan="scan" @back="back" />
  42. </view>
  43. </template>
  44. <script>
  45. import { wxScanCode } from '@/common/utils/util.js'
  46. import zhifutanchuan from '@/components/zhifutanchuan.vue'
  47. export default {
  48. components: {
  49. zhifutanchuan
  50. },
  51. data() {
  52. return {
  53. orderId: null,
  54. wbId: null,
  55. refresherTriggered: false,
  56. loadStatus: 0,
  57. errorText: '',
  58. detail: null,
  59. canScanCode: 0,
  60. timeout: null,
  61. timeoutNum: 0,
  62. payType: 1,
  63. state: 0
  64. }
  65. },
  66. onLoad({ handleOrderId, wbId }) {
  67. this.orderId = handleOrderId
  68. this.wbId = wbId
  69. this.getDetail()
  70. this.crossPage.$on('reScanCode', () => {
  71. this.scanCode()
  72. })
  73. },
  74. onUnload() {
  75. if (this.timeout) {
  76. clearTimeout(this.timeout)
  77. }
  78. },
  79. methods: {
  80. scan() {
  81. if (this.timeout) {
  82. clearTimeout(this.timeout)
  83. }
  84. this.scanCode()
  85. },
  86. back() {
  87. if (this.timeout) {
  88. clearTimeout(this.timeout)
  89. }
  90. this.$navToPage(
  91. {
  92. url: `/packageMaterial/pages/index?type=M`
  93. },
  94. 'reLaunch'
  95. )
  96. },
  97. getDetail() {
  98. let url = '',
  99. params = {}
  100. if (this.wbId) {
  101. url = '/engin/material/detail'
  102. params.id = this.orderId
  103. } else {
  104. url = '/pay/getOrder'
  105. params.orderId = this.orderId
  106. }
  107. this.$api
  108. .post(url, params)
  109. .then(res => {
  110. this.detail = res.data
  111. this.loadStatus = 0
  112. })
  113. .catch(res => {
  114. this.errorText = res.message
  115. this.loadStatus = 2
  116. })
  117. .finally(res => {
  118. this.refresherTriggered = false
  119. })
  120. },
  121. // 取消订单
  122. cancelOrder() {
  123. this.$modal({
  124. content: '确认取消订单吗?'
  125. })
  126. .then(() => {
  127. this.$api
  128. .post('/pay/cancel', {
  129. orderId: this.orderId
  130. })
  131. .then(res => {
  132. this.$successToast()
  133. this.$navToPage(
  134. {
  135. delta: 1
  136. },
  137. 'navigateBack'
  138. )
  139. })
  140. })
  141. .catch(() => {})
  142. },
  143. // 扫码
  144. async scanCode() {
  145. if (this.canScanCode > 0) return this.$toast(`请等待${this.canScanCode}秒后重试`)
  146. var codeVal = await wxScanCode(['qrCode'])
  147. this.submitData(codeVal)
  148. },
  149. // 下单
  150. submitData(code) {
  151. let url = ''
  152. if (this.wbId) {
  153. url = '/engin/material/paid'
  154. } else {
  155. url = '/pay/paid'
  156. }
  157. this.$api
  158. .post(url, {
  159. authCode: code,
  160. orderId: this.orderId,
  161. payType: 'WECHAT'
  162. })
  163. .then(res => {
  164. if (this.state == 0) {
  165. this.state = 1
  166. }
  167. // 返回true,则支付成功
  168. if (res.data) {
  169. this.state = 2
  170. }
  171. // 返回false,轮询3次
  172. else {
  173. this.timeout = setTimeout(() => {
  174. this.submitData(code)
  175. }, 1000)
  176. }
  177. })
  178. .catch(res => {
  179. this.$tips(res.message)
  180. })
  181. },
  182. confirmPay() {
  183. let url = ''
  184. if (this.wbId) {
  185. url = '/engin/material/paid'
  186. } else {
  187. url = '/pay/paid'
  188. }
  189. this.$api
  190. .post(url, {
  191. authCode: '',
  192. orderId: this.orderId,
  193. payType: 'LINE'
  194. })
  195. .then(res => {
  196. if (res.data) {
  197. this.$navToPage({
  198. url: `/packageMaterial/pages/sale/result?handleOrderId=${this.orderId}&result=1&wbId=${this.wbId || ''}`
  199. })
  200. } else {
  201. this.$navToPage({
  202. url: `/packageMaterial/pages/sale/result?handleOrderId=${this.orderId}&result=0&wbId=${this.wbId || ''}`
  203. })
  204. }
  205. })
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .card {
  212. @include zj-card;
  213. }
  214. .materials-container {
  215. padding: 30rpx;
  216. .title {
  217. text-align: center;
  218. margin-top: 30rpx;
  219. .t1 {
  220. font-size: 32rpx;
  221. font-weight: 500;
  222. }
  223. .t2 {
  224. font-size: 40rpx;
  225. color: $minor-color;
  226. margin-top: 20rpx;
  227. text {
  228. font-size: 56rpx;
  229. font-weight: 500;
  230. }
  231. }
  232. }
  233. .id {
  234. margin-top: 50rpx;
  235. text {
  236. color: $sec-font;
  237. }
  238. }
  239. .product {
  240. background: #f5f5f5;
  241. border-radius: 12rpx;
  242. padding: 20rpx;
  243. margin-top: 20rpx;
  244. .it {
  245. display: flex;
  246. align-items: flex-end;
  247. margin-bottom: 20rpx;
  248. .name {
  249. flex: 1;
  250. font-size: 28rpx;
  251. font-weight: 500;
  252. text {
  253. color: $sec-font;
  254. margin-left: 12rpx;
  255. font-weight: normal;
  256. }
  257. }
  258. .price {
  259. margin-left: 30rpx;
  260. font-size: 28rpx;
  261. font-weight: 500;
  262. }
  263. }
  264. .total {
  265. display: flex;
  266. align-items: center;
  267. justify-content: flex-end;
  268. margin-top: 30rpx;
  269. .text {
  270. font-size: 28rpx;
  271. color: $sec-font;
  272. }
  273. .price {
  274. font-size: 28rpx;
  275. color: $minor-color;
  276. font-weight: 500;
  277. }
  278. }
  279. }
  280. .row {
  281. margin-top: 20rpx;
  282. line-height: 40rpx;
  283. display: flex;
  284. font-size: 28rpx;
  285. text {
  286. color: $sec-font;
  287. flex-shrink: 0;
  288. line-height: 40rpx;
  289. }
  290. }
  291. }
  292. .pay-container {
  293. padding: 30rpx;
  294. .top {
  295. margin-bottom: 40rpx;
  296. }
  297. .item {
  298. display: flex;
  299. align-items: center;
  300. justify-content: space-between;
  301. margin: 30rpx 0;
  302. .left {
  303. display: flex;
  304. align-items: center;
  305. .iconfont {
  306. font-size: 44rpx;
  307. color: #43c93e;
  308. }
  309. .text {
  310. margin-left: 18rpx;
  311. font-size: 32rpx;
  312. }
  313. }
  314. .right {
  315. .iconfont {
  316. font-size: 40rpx;
  317. color: $sec-font;
  318. &.active {
  319. color: $theme-color;
  320. }
  321. }
  322. }
  323. }
  324. }
  325. </style>