您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

add-equity-details.vue 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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><text>{{state.params['productIntro']}}</text></view> -->
  7. <view><text>权益介绍:</text><rich-text :nodes="state.params['productIntro']" class="last" /></view>
  8. <view><text>卖点:</text><text>{{state.params['sellingPoint']}}</text></view>
  9. <view><text>开始时间:</text><text>{{state.params['startDate']}}</text></view>
  10. <view><text>结束时间:</text><text>{{state.params['endDate']}}</text></view>
  11. </view>
  12. <view style="margin-top: 30rpx" class="action">
  13. <button type="default" class="button" @click="buy()">
  14. 购买
  15. </button>
  16. </view>
  17. </view>
  18. </template>
  19. <script setup lang="ts">
  20. import { reactive } from "vue";
  21. import { onLoad } from "@dcloudio/uni-app";
  22. import { addEquityListApi, getOpenidApi, PAYMENTORDERAPPLY, equityPaymentOrderApi, equityPaymentTestApi } from "@/utils/network/api.js";
  23. import {
  24. request
  25. } from "@/utils/network/request.js";
  26. import {
  27. getItem,
  28. StorageKeys,
  29. } from "@/utils/storage";
  30. import {
  31. stringToJson
  32. } from "@/utils/network/encryption";
  33. import { msg } from "@/utils/utils";
  34. const state = reactive({
  35. id: "", //支付id
  36. params: {}, //上一个页面传递过来的参数
  37. });
  38. onLoad((options) => {
  39. state.params = JSON.parse(decodeURIComponent(options.params))
  40. state.params['startDate'] = state.params['startDate'].replace("T", ' ')
  41. state.params['endDate'] = state.params['endDate'].replace("T", ' ')
  42. console.log("options", state.params)
  43. })
  44. const buy = () => {
  45. const options = {
  46. type: 2,
  47. data: {
  48. "type": 1,
  49. "openId": getItem(StorageKeys.OpenId),
  50. "equityId": state.params['equtyId']
  51. },
  52. method: 'POST',
  53. showLoading: true,
  54. }
  55. // 权益购买入参有个属性是type:1,代表查询是否已经买过了权益,返回的数据中hasData:true表示买过了,如果hasData:false表示没买过。type:2,表示购买
  56. request(addEquityListApi, options).then((res) => {
  57. const data = stringToJson(res.bizContent);
  58. console.log("加购", data.hasData)
  59. if (data.hasData) {
  60. uni.showModal({
  61. title: '提示',
  62. content: '重复购买此产品',
  63. success: function (res) {
  64. if (res.confirm) {
  65. console.log('用户点击确定');
  66. chooseBuy()
  67. } else if (res.cancel) {
  68. console.log('用户点击取消');
  69. }
  70. }
  71. });
  72. } else {
  73. chooseBuy()
  74. }
  75. })
  76. }
  77. const chooseBuy = () => {
  78. const options = {
  79. type: 2,
  80. data: {
  81. "type": 2,
  82. "openId": getItem(StorageKeys.OpenId),
  83. "equityId": state.params['equtyId']
  84. },
  85. method: 'POST',
  86. showLoading: true,
  87. }
  88. // 权益购买入参有个属性是type:1,代表查询是否已经买过了权益,返回的数据中hasData:true表示买过了,如果hasData:false表示没买过。type:2,表示购买
  89. request(addEquityListApi, options).then((res) => {
  90. const data = stringToJson(res.bizContent);
  91. console.log("购买2", data)
  92. state.id = data.info
  93. // 权益支付下单
  94. equityPaymentOrderRequest()
  95. })
  96. }
  97. // 权益支付检测
  98. const equityPaymentTestRequest = () => {
  99. const options = {
  100. type: 2,
  101. data: {
  102. id: state.id,
  103. },
  104. method: 'POST',
  105. showLoading: true,
  106. }
  107. return new Promise(async (resolve, reject) => {
  108. const res = await request(equityPaymentTestApi, options);
  109. const data = stringToJson(res.bizContent);
  110. resolve(data);
  111. }).catch((error) => {
  112. reject(error);
  113. });
  114. }
  115. // 权益支付下单
  116. const equityPaymentOrderRequest = () => {
  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. }
  189. </script>
  190. <style scoped lang="scss">
  191. .allContent {
  192. background-color: #EEF7F7;
  193. height: 100vh;
  194. padding: 30rpx 0;
  195. width: 100%;
  196. overflow-x: auto;
  197. }
  198. .list-item {
  199. width: 95%;
  200. border-radius: 10rpx;
  201. margin: 0rpx auto;
  202. font-size: 28rpx;
  203. border: 1rpx solid #ccc;
  204. padding: 12rpx;
  205. box-sizing: border-box;
  206. background-color: white;
  207. }
  208. .list-item>view {
  209. margin-bottom: 20rpx;
  210. display: flex;
  211. align-items: center;
  212. }
  213. .list-item>view>text:first-child {
  214. width: 26%;
  215. display: inline-block;
  216. }
  217. .list-item>view>text:last-child {
  218. width: 74%;
  219. display: inline-block;
  220. word-break: break-all;
  221. }
  222. .last {
  223. width: 74%;
  224. display: inline-block;
  225. word-break: break-all;
  226. }
  227. .action {
  228. padding-bottom: 100rpx;
  229. width: 90%;
  230. margin: 0 auto;
  231. .button {
  232. height: 80rpx;
  233. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  234. border-radius: 40rpx;
  235. font-size: 32rpx;
  236. font-weight: 400;
  237. color: #ffffff;
  238. line-height: 80rpx;
  239. }
  240. }
  241. </style>