You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

orderPayment - 副本.vue 7.3KB

2 lat temu
2 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="content">
  3. <custom-header title="订单详情" :back="config.hasReturn === 'true'"></custom-header>
  4. <div style="padding: 20rpx" v-if='isShow'>
  5. <view class="title">
  6. 订单详情
  7. </view>
  8. <view class="container">
  9. <template v-for='(item,index) in formData'>
  10. <view class="detail-item" :key='index' v-if='item.value !== "" && item.value !== undefined'>
  11. <text>{{item.label}}</text>
  12. <text class="amount">{{item.key === 'amount'? '¥'+ item.value:item.value}}</text>
  13. </view>
  14. </template>
  15. </view>
  16. <view class="payment-total">
  17. <text>实付款</text>
  18. <text class="amount">¥{{amount}}</text>
  19. </view>
  20. <button type="success" class="btn-txt btn" @click="submit">确认办理</button>
  21. </div>
  22. </div>
  23. </template>
  24. <script setup lang='ts'>
  25. import {
  26. unifyTemplate
  27. } from '@/hooks/unifyTemplate'
  28. import {
  29. reactive,
  30. ref
  31. } from 'vue'
  32. import {
  33. onLoad
  34. } from '@dcloudio/uni-app'
  35. import {
  36. request,
  37. myJsonp,
  38. toWeixin
  39. } from '@/utils/network/request'
  40. import {
  41. setToken,
  42. getToken
  43. } from '@/utils/storage'
  44. const {
  45. CustomHeader, //头部组件
  46. initData, //初始化数据
  47. isShow, //是否展示formBuilderVue组件
  48. qdOrderVal //qdOrder中数据 ref
  49. } = unifyTemplate() //初始化数据
  50. // import {
  51. // request
  52. // } from '../../static/js/network/request'
  53. let formData = reactive < any > ([{
  54. label: '产品名',
  55. value: '',
  56. key: "product",
  57. key1: 'promoteName',
  58. }, {
  59. label: '车牌号',
  60. key: "vehiclePlate",
  61. value: '贵'
  62. }, {
  63. label: '车主姓名',
  64. key: "ownerName",
  65. value: ''
  66. }, {
  67. label: '邮寄地址',
  68. key: "orderInfoExt",
  69. key1: 'region,address',
  70. default: "不邮寄",
  71. value: ''
  72. }, {
  73. label: '产品金额',
  74. key: "amount",
  75. format: (val) => {
  76. return val * 0.01
  77. },
  78. value: '0'
  79. }, ])
  80. // 实付款
  81. const amount = ref < any > ('')
  82. let config = ref < any > ({
  83. submitName: '提交',
  84. titleWidth: 160
  85. })
  86. onLoad((opin) => {
  87. // 初始化数据
  88. initData(opin, 4).then(async data => {
  89. await login(data)
  90. detectAliPay()
  91. getOrderInfo(data.qdOrder.qtOrderNo)
  92. delete data.config.tableConfig
  93. config.value = Object.assign(data.config, config.value)
  94. })
  95. })
  96. // 无感登录,如果没有登录调用登录
  97. async function login(orderData) {
  98. const token = getToken();
  99. if (token) {
  100. return
  101. }
  102. let data = {
  103. userType: '',
  104. account: ''
  105. }
  106. if (orderData.order.userType === 'PERSONAL_USER') {
  107. // 个人办理
  108. data.userType = 'PERSONAL'
  109. data.account = orderData.order.customerTel
  110. } else {
  111. // 单位办理
  112. data.userType = 'ENTERPRISE'
  113. data.account = orderData.order.customerIdnum
  114. }
  115. await request('abaf0013caa24dafad12b0f571e8ee40', {
  116. data,
  117. }).then((res) => {
  118. if (res.statusCode === 0) {
  119. let bizContent = JSON.parse(res.bizContent)
  120. // 保存token
  121. setToken(bizContent.accessToken)
  122. }
  123. // contractTesting(qdOrderVal.value.qdOrderNo, jumpPage)
  124. })
  125. }
  126. // 订单已支付
  127. async function detectAliPay() {
  128. await request('56', {
  129. data: {
  130. orderId: qdOrderVal.value.qdOrderNo
  131. }
  132. }).then((res) => {
  133. if (res.statusCode === 0) {
  134. let data = JSON.parse(res.bizContent)
  135. if (data.tradeState === 'SUCCESS') {
  136. let {
  137. jumpPage
  138. } = config.value
  139. contractTesting(qdOrderVal.value.qdOrderNo, jumpPage)
  140. }
  141. }
  142. // contractTesting(qdOrderVal.value.qdOrderNo, jumpPage)
  143. })
  144. }
  145. // 数据处理
  146. function getOrderInfo(orderId) {
  147. request('8', {
  148. data: {
  149. orderId
  150. }
  151. }).then((res) => {
  152. let data = JSON.parse(res.bizContent)
  153. amount.value = data.amount * 0.01
  154. formData.forEach(item => {
  155. let itemData = data[item.key]
  156. if (typeof itemData === 'object') {
  157. if (item.key1.includes(',')) {
  158. let str = ''
  159. item.key1.split(',').forEach(listItem => {
  160. str += itemData[listItem] || ''
  161. })
  162. itemData = str
  163. } else {
  164. itemData = itemData[item.key1]
  165. }
  166. }
  167. if (item.format) {
  168. itemData = item.format(itemData)
  169. }
  170. item.value = itemData || item.default
  171. })
  172. isShow.value = true;
  173. })
  174. }
  175. //提交
  176. function submit() {
  177. // console.log('提交内容', item)
  178. uni.showLoading({
  179. title: '正在支付...',
  180. mask: true
  181. })
  182. // let {
  183. // jumpPage
  184. // } = config.value
  185. // setTimeout(() => {
  186. // uni.hideLoading()
  187. // contractTesting(qdOrderVal.value.qdOrderNo, jumpPage)
  188. // }, 1000)
  189. // 根据公网ip获取支付地址
  190. myJsonp({
  191. url: 'https://www.taobao.com/help/getip.php',
  192. success(res) {
  193. console.log(res)
  194. // const data = {
  195. // fee: 1,
  196. // spbillCreateIp: res.ip,
  197. // }
  198. request('56', {
  199. data: {
  200. orderId: qdOrderVal.value.qdOrderNo,
  201. payConfigId: '6a9a54bc01f6443faea7ffe132b1234',
  202. h5Type: 'Wap',
  203. spbillCreateIp: res.ip,
  204. }
  205. }).then((res) => {
  206. uni.hideLoading()
  207. if (res.statusCode === 0) {
  208. let data = JSON.parse(res.bizContent)
  209. window.open(data.h5Url, '_blank')
  210. }
  211. // contractTesting(qdOrderVal.value.qdOrderNo, jumpPage)
  212. })
  213. }
  214. })
  215. }
  216. // 签约检测
  217. function contractTesting(qdOrderNo, jumpPage) {
  218. const data = {
  219. qdOrderNo,
  220. }
  221. request('fdfbdddba6ec49f8b451cf2e299b4feb', {
  222. data,
  223. }).then((res) => {
  224. if (res.statusCode === 0) {
  225. const data = JSON.parse(res.bizContent)
  226. if (data.signStatus === 1 && data.accountStatus === 1 && data.bindStatus === 1) {
  227. // 上面三值都为1才进行下一步,否则进行签约初始化
  228. if (!jumpPage) return
  229. uni.navigateTo({
  230. url: '/' + jumpPage,
  231. animationType: 'pop-in',
  232. animationDuration: 500
  233. })
  234. /* 自定义返回 */
  235. } else {
  236. // 进行签约初始化
  237. signingInitialization(qdOrderNo)
  238. }
  239. // qdOrderStore.orderInfo.value.orderId = JSON.parse(res.bizContent).orderId
  240. // 通过检测
  241. }
  242. })
  243. }
  244. // 签约初始化
  245. function signingInitialization(qdOrderNo) {
  246. const data = {
  247. qdOrderNo
  248. }
  249. request('94569071cf814517908cd35693f1f2e1', {
  250. data,
  251. }).then((res) => {
  252. if (res.statusCode === 0) {
  253. const data = JSON.parse(res.bizContent)
  254. if (data.returnType === 0) {
  255. // 0-无需跳转,关闭H5即可 1-需跳转至返回url
  256. // const opened = window.open('about:blank', '_self');
  257. // opened.opener = null;
  258. // opened.close();
  259. closeWin()
  260. } else {
  261. window.open(data.signUrl, '_self')
  262. }
  263. }
  264. })
  265. }
  266. // 关闭当前页面方法
  267. function closeWin() {
  268. // @ts-ignore
  269. var jWeixin = import('jweixin-module')
  270. // @ts-ignore
  271. jWeixin.miniProgram.getEnv(function(res) {
  272. if (res.miniprogram) {
  273. // @ts-ignore
  274. jWeixin.miniProgram.navigateTo({
  275. url: '/path/to/page'
  276. })
  277. } else {
  278. const opened = window.open('about:blank', '_self');
  279. opened.opener = null;
  280. opened.close()
  281. }
  282. })
  283. }
  284. </script>
  285. <style lang='scss' scoped>
  286. .title {
  287. font-size: 30rpx;
  288. margin-left: 30rpx;
  289. }
  290. .container {
  291. padding: 10px;
  292. font-size: 14px;
  293. .detail-item {
  294. display: flex;
  295. align-items: center;
  296. justify-content: space-between;
  297. padding: 5px;
  298. margin-bottom: 8px;
  299. border-bottom: 1px solid #ccc;
  300. }
  301. }
  302. .payment-total {
  303. text-align: right;
  304. padding: 0 10px 20px;
  305. }
  306. text {
  307. margin-left: 10px;
  308. }
  309. .amount {
  310. color: #1AAC1B;
  311. max-width: 450rpx;
  312. }
  313. .btn {
  314. height: 80rpx;
  315. opacity: 1;
  316. border-radius: 100rpx;
  317. margin: 20rpx 20rpx 20rpx 20rpx;
  318. }
  319. .btn-txt {
  320. background: #1AAC1B;
  321. margin: 10px;
  322. color: #FFFFFF;
  323. font-size: 28rpx;
  324. }
  325. </style>