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.

equityList.vue 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view>
  3. <view v-for="(item, index) in listData" :key="index" @click="onClick(item)" :data-code="item" class="item">
  4. <view style="display: flex;justify-content: space-between;">
  5. <text>{{ item.name }}</text><text>></text>
  6. </view>
  7. <view style="display: flex;justify-content: flex-end;margin-top: 6rpx;">
  8. <!-- 是否支付 1-已支付,2-未支付支付,3-已取消,4-已下单,未支付 -->
  9. <text class="btn" v-if="item.isPay==2"
  10. @click.stop="chooseBuy(item.equityId)">去支付</text>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script setup lang='ts'>
  16. import { reactive } from "vue";
  17. import {
  18. getItem,StorageKeys
  19. } from "@/utils/storage";
  20. import {
  21. ref
  22. } from 'vue';
  23. import {
  24. requestNew
  25. } from "@/utils/network/request.js";
  26. import {
  27. equitypurchasepage,equitypurchase,getOpenId,paymentequityapplyapp,payequitydetection
  28. } from "@/utils/network/api.js";
  29. import {
  30. stringToJson
  31. } from "@/utils/network/encryption";
  32. import { msg } from "@/utils/utils";
  33. import {onShow} from "@dcloudio/uni-app";
  34. let listData = ref([])
  35. const state = reactive({
  36. id: "", //支付id
  37. });
  38. onShow(()=>{
  39. query()
  40. })
  41. function query(){
  42. //卡券渠道类型获取单项权益列表
  43. requestNew(equitypurchasepage, {
  44. type: 2,
  45. data: {
  46. couponAgencyType: ['TUHU', 'ZFB'],
  47. mobile: getItem('mobile').toString()
  48. },
  49. method: "POST",
  50. showLoading: true,
  51. }).then((item) => {
  52. let res = item
  53. console.log(res, '=========');
  54. listData.value = res.result
  55. })
  56. }
  57. function onClick(singId: any) {
  58. uni.navigateTo({
  59. url: '/subpackage/service/equity/equity?singleEquityId=' + singId.singleEquityId +
  60. '&couponAgencyType=' + singId.couponAgencyType + '&couponId=' + singId.couponId + '&equityId=' + singId.equityId,
  61. })
  62. }
  63. const chooseBuy = (equityId) => {
  64. const options = {
  65. type: 2,
  66. data: {
  67. "openId": getItem(StorageKeys.OpenId),
  68. "equityId": equityId
  69. },
  70. method: 'POST',
  71. showLoading: true,
  72. }
  73. // 权益购买入参有个属性是type:1,代表查询是否已经买过了权益,返回的数据中hasData:true表示买过了,如果hasData:false表示没买过。type:2,表示购买
  74. requestNew(equitypurchase, options).then((res) => {
  75. const data = res;
  76. console.log("购买2", data)
  77. state.id = data.id
  78. // 权益支付下单
  79. equityPaymentOrderRequest()
  80. })
  81. }
  82. // 权益支付下单
  83. const equityPaymentOrderRequest = () => {
  84. // #ifdef MP-WEIXIN
  85. uni.login({
  86. provider: "weixin",
  87. success: function (e) {
  88. const options1 = {
  89. type: 2,
  90. data: {
  91. "jsCode": e.code
  92. },
  93. method: "POST",
  94. showLoading: true,
  95. };
  96. requestNew(getOpenId, options1).then((res) => {
  97. console.log("state.id",state.id)
  98. console.log("state.id",res)
  99. const result = res;
  100. const openidData = stringToJson(result.data);
  101. console.log("openidData",openidData)
  102. const options = {
  103. type: 2,
  104. data: {
  105. id: state.id,
  106. payType: "EQUITY",
  107. wxOpenid: openidData.openid,
  108. // openId: openidData.openid,
  109. },
  110. method: 'POST',
  111. showLoading: true,
  112. }
  113. requestNew(paymentequityapplyapp, options).then((res) => {
  114. const data = res;
  115. console.log("权益支付下单", data)
  116. if (data.info == "购买权益记录已支付") {
  117. uni.showModal({
  118. title: '提示',
  119. content: data.info,
  120. showCancel: false,
  121. success: function (res) {
  122. if (res.confirm) {
  123. uni.navigateBack({
  124. delta: 2
  125. })
  126. }
  127. }
  128. });
  129. } else {
  130. uni.requestPayment({
  131. provider: "wxpay",
  132. orderInfo: "",
  133. timeStamp: data.timestamp,
  134. nonceStr: data.noncestr,
  135. package: data.wxPackage ? data.wxPackage : "",
  136. signType: data.signType,
  137. paySign: data.sign,
  138. success: function (e) {
  139. console.log("支付成功", res);
  140. // 权益支付检测
  141. equityPaymentTestRequest().then((item : any) => {
  142. console.log("权益支付检测", data)
  143. msg("权益产品购买成功")
  144. // 重新查询一遍
  145. query()
  146. })
  147. },
  148. fail: function (err) {
  149. confirm(err, () => { }, "支付失败", false);
  150. },
  151. })
  152. }
  153. })
  154. })
  155. },
  156. })
  157. // #endif
  158. // #ifdef MP-ALIPAY
  159. my.getAuthCode({
  160. scopes: 'auth_base',
  161. success: res => {
  162. const optionsUser = {
  163. type: 2,
  164. data: {
  165. payConfigId: aliPayConfigIdTwo,
  166. code: res.authCode
  167. },
  168. method: "POST",
  169. showLoading: true,
  170. };
  171. console.log('支付宝用户编号请求:', optionsUser)
  172. request(obtainUserId, optionsUser).then((res) => {
  173. console.log('支付宝用户编号返回:', res)
  174. const data = stringToJson(res.bizContent);
  175. console.log("data", data)
  176. const optionsali = {
  177. type: 2,
  178. data: {
  179. id: state.id,
  180. payType: "EQUITY",
  181. wxOpenid: data.openId,
  182. },
  183. method: "POST",
  184. showLoading: true,
  185. };
  186. console.log('支付下单请求:', optionsali)
  187. requestNew(paymentequityapplyapp, optionsali).then((res) => {
  188. const data = stringToJson(res.bizContent);
  189. console.log('支付下单返回:', data)
  190. my.tradePay({
  191. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  192. tradeNO: data.tranPackage,
  193. success: res => {
  194. console.log("支付成功", res);
  195. if (res.resultCode != "6001") {
  196. // 权益支付检测
  197. equityPaymentTestRequest().then((item : any) => {
  198. console.log("权益支付检测", data)
  199. msg("权益产品购买成功,到【我的】权益查看")
  200. setTimeout(() => {
  201. uni.navigateBack({
  202. delta: 2
  203. })
  204. }, 2000)
  205. })
  206. }
  207. },
  208. fail: res => {
  209. console.log("支付失败", res);
  210. },
  211. });
  212. });
  213. });
  214. },
  215. fail: err => {
  216. console.log('my.getAuthCode 调用失败', err)
  217. }
  218. });
  219. // #endif
  220. }
  221. // 权益支付检测
  222. const equityPaymentTestRequest = () => {
  223. const options = {
  224. type: 2,
  225. data: {
  226. id: state.id,
  227. },
  228. method: 'POST',
  229. showLoading: true,
  230. }
  231. return new Promise(async (resolve, reject) => {
  232. const res = await requestNew(payequitydetection, options);
  233. const data = res;
  234. resolve(data);
  235. }).catch((error) => {
  236. reject(error);
  237. });
  238. }
  239. </script>
  240. <style lang='scss' scoped>
  241. .item{
  242. background-color: #22dbc8;
  243. color: white;
  244. border-radius: 20rpx;
  245. padding: 15px 30rpx;
  246. margin: 20rpx;
  247. font-size: 28rpx;
  248. }
  249. .btn {
  250. height: 50rpx;
  251. line-height: 50rpx;
  252. border-radius: 30rpx;
  253. padding: 0 24rpx;
  254. font-size: 23rpx;
  255. box-sizing: border-box;
  256. margin-right: 12rpx;
  257. border: 1px solid #fff;
  258. color: #fff;
  259. display: inline-block;
  260. }
  261. </style>