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.

add-equity-details.vue 8.1KB

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