Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

add-equity-details.vue 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view class="allContent">
  3. <view class="list-item">
  4. <view><text>权益名称:</text><text>{{state.params['equityName']}}</text></view>
  5. <view><text>权益金额:</text><text>¥{{state.params['discountPrice']* 0.01}}</text></view>
  6. <view><text>权益介绍:</text><rich-text :nodes="state.params['productIntro']" class="last" /></view>
  7. <view><text>卖点:</text><text>{{state.params['sellingPoint']}}</text></view>
  8. <view><text>开始时间:</text><text>{{state.params['startDate']}}</text></view>
  9. <view><text>结束时间:</text><text>{{state.params['endDate']}}</text></view>
  10. </view>
  11. <view style="margin-top: 30rpx" class="action">
  12. <button type="default" class="button" @click="buy()">
  13. 购买
  14. </button>
  15. </view>
  16. </view>
  17. </template>
  18. <script setup lang="ts">
  19. import { reactive } from "vue";
  20. import { onLoad } from "@dcloudio/uni-app";
  21. import { equitypurchase, getOpenId, paymentequityapplyapp, payequitydetection, aliPayConfigIdTwo, obtainUserId } from "@/utils/network/api.js";
  22. import {
  23. request, requestNew
  24. } from "@/utils/network/request.js";
  25. import {
  26. getItem,
  27. StorageKeys,
  28. } from "@/utils/storage";
  29. import {
  30. stringToJson
  31. } from "@/utils/network/encryption";
  32. import { msg } from "@/utils/utils";
  33. const state = reactive({
  34. id: "", //支付id
  35. params: {}, //上一个页面传递过来的参数
  36. });
  37. onLoad((options) => {
  38. state.params = JSON.parse(decodeURIComponent(options.params))
  39. state.params['startDate'] = state.params['startDate'].replace("T", ' ')
  40. state.params['endDate'] = state.params['endDate'].replace("T", ' ')
  41. console.log("options", state.params)
  42. })
  43. const buy = () => {
  44. if(state.params['hasDate']){
  45. uni.showModal({
  46. title: '提示',
  47. content: '重复购买此权益',
  48. success: function (res) {
  49. if (res.confirm) {
  50. console.log('用户点击确定');
  51. chooseBuy()
  52. } else if (res.cancel) {
  53. console.log('用户点击取消');
  54. }
  55. }
  56. });
  57. }else{
  58. chooseBuy()
  59. }
  60. }
  61. const chooseBuy = () => {
  62. const options = {
  63. type: 2,
  64. data: {
  65. "openId": getItem(StorageKeys.OpenId),
  66. "equityId": state.params['equtyId']
  67. },
  68. method: 'POST',
  69. showLoading: true,
  70. }
  71. // 权益购买入参有个属性是type:1,代表查询是否已经买过了权益,返回的数据中hasData:true表示买过了,如果hasData:false表示没买过。type:2,表示购买
  72. requestNew(equitypurchase, options).then((res) => {
  73. const data = res;
  74. console.log("购买2", data)
  75. state.id = data.id
  76. // 权益支付下单
  77. equityPaymentOrderRequest()
  78. })
  79. }
  80. // 权益支付检测
  81. const equityPaymentTestRequest = () => {
  82. const options = {
  83. type: 2,
  84. data: {
  85. id: state.id,
  86. },
  87. method: 'POST',
  88. showLoading: true,
  89. }
  90. return new Promise(async (resolve, reject) => {
  91. const res = await requestNew(payequitydetection, options);
  92. const data = res;
  93. resolve(data);
  94. }).catch((error) => {
  95. reject(error);
  96. });
  97. }
  98. // 权益支付下单
  99. const equityPaymentOrderRequest = () => {
  100. // #ifdef MP-WEIXIN
  101. uni.login({
  102. provider: "weixin",
  103. success: function (e) {
  104. const options1 = {
  105. type: 2,
  106. data: {
  107. "jsCode": e.code
  108. },
  109. method: "POST",
  110. showLoading: true,
  111. };
  112. requestNew(getOpenId, options1).then((res) => {
  113. console.log("state.id",state.id)
  114. console.log("state.id",res)
  115. const result = res;
  116. const openidData = stringToJson(result.data);
  117. console.log("openidData",openidData)
  118. const options = {
  119. type: 2,
  120. data: {
  121. id: state.id,
  122. payType: "EQUITY",
  123. wxOpenid: openidData.openid
  124. },
  125. method: 'POST',
  126. showLoading: true,
  127. }
  128. requestNew(paymentequityapplyapp, options).then((res) => {
  129. const data = res;
  130. console.log("权益支付下单", data)
  131. if (data.info == "购买权益记录已支付") {
  132. uni.showModal({
  133. title: '提示',
  134. content: data.info,
  135. showCancel: false,
  136. success: function (res) {
  137. if (res.confirm) {
  138. uni.navigateBack({
  139. delta: 2
  140. })
  141. }
  142. }
  143. });
  144. } else {
  145. uni.requestPayment({
  146. provider: "wxpay",
  147. orderInfo: "",
  148. timeStamp: data.timestamp,
  149. nonceStr: data.noncestr,
  150. package: data.wxPackage ? data.wxPackage : "",
  151. signType: data.signType,
  152. paySign: data.sign,
  153. success: function (e) {
  154. console.log("支付成功", res);
  155. // 权益支付检测
  156. equityPaymentTestRequest().then((item : any) => {
  157. console.log("权益支付检测", data)
  158. msg("权益产品购买成功,到【我的】权益查看")
  159. setTimeout(() => {
  160. uni.navigateBack({
  161. delta: 2
  162. })
  163. }, 2000)
  164. })
  165. },
  166. fail: function (err) {
  167. confirm(err, () => { }, "支付失败", false);
  168. },
  169. })
  170. }
  171. })
  172. })
  173. },
  174. })
  175. // #endif
  176. // #ifdef MP-ALIPAY
  177. my.getAuthCode({
  178. scopes: 'auth_base',
  179. success: res => {
  180. const optionsUser = {
  181. type: 2,
  182. data: {
  183. payConfigId: aliPayConfigIdTwo,
  184. code: res.authCode
  185. },
  186. method: "POST",
  187. showLoading: true,
  188. };
  189. console.log('支付宝用户编号请求:', optionsUser)
  190. requestNew(obtainUserId, optionsUser).then((res) => {
  191. console.log('支付宝用户编号返回:', res)
  192. const data = res;
  193. console.log("data", data)
  194. const optionsali = {
  195. type: 2,
  196. data: {
  197. id: state.id,
  198. payType: "EQUITY",
  199. wxOpenid: data.openId,
  200. },
  201. method: "POST",
  202. showLoading: true,
  203. };
  204. console.log('支付下单请求:', optionsali)
  205. requestNew(paymentequityapplyapp, optionsali).then((res) => {
  206. const data = stringToJson(res.bizContent);
  207. console.log('支付下单返回:', data)
  208. my.tradePay({
  209. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  210. tradeNO: data.tranPackage,
  211. success: res => {
  212. console.log("支付成功", res);
  213. if (res.resultCode != "6001") {
  214. // 权益支付检测
  215. equityPaymentTestRequest().then((item : any) => {
  216. console.log("权益支付检测", data)
  217. msg("权益产品购买成功,到【我的】权益查看")
  218. setTimeout(() => {
  219. uni.navigateBack({
  220. delta: 2
  221. })
  222. }, 2000)
  223. })
  224. }
  225. },
  226. fail: res => {
  227. console.log("支付失败", res);
  228. },
  229. });
  230. });
  231. });
  232. },
  233. fail: err => {
  234. console.log('my.getAuthCode 调用失败', err)
  235. }
  236. });
  237. // #endif
  238. }
  239. </script>
  240. <style scoped lang="scss">
  241. .allContent {
  242. background-color: #EEF7F7;
  243. height: 100vh;
  244. padding: 30rpx 0;
  245. width: 100%;
  246. overflow-x: auto;
  247. }
  248. .list-item {
  249. width: 95%;
  250. border-radius: 10rpx;
  251. margin: 0rpx auto;
  252. font-size: 28rpx;
  253. border: 1rpx solid #ccc;
  254. padding: 12rpx;
  255. box-sizing: border-box;
  256. background-color: white;
  257. }
  258. .list-item>view {
  259. margin-bottom: 20rpx;
  260. display: flex;
  261. align-items: center;
  262. }
  263. .list-item>view>text:first-child {
  264. width: 26%;
  265. display: inline-block;
  266. }
  267. .list-item>view>text:last-child {
  268. width: 74%;
  269. display: inline-block;
  270. word-break: break-all;
  271. }
  272. .last {
  273. width: 74%;
  274. display: inline-block;
  275. word-break: break-all;
  276. }
  277. .action {
  278. padding-bottom: 100rpx;
  279. width: 90%;
  280. margin: 0 auto;
  281. .button {
  282. height: 80rpx;
  283. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  284. border-radius: 40rpx;
  285. font-size: 32rpx;
  286. font-weight: 400;
  287. color: #ffffff;
  288. line-height: 80rpx;
  289. }
  290. }
  291. </style>