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.

product-detail.vue 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <template>
  2. <navBar title="产品详情"></navBar>
  3. <navBgCar></navBgCar>
  4. <view class="content-wrap">
  5. <view class="ul-item">
  6. <image style="width: 100%; height: 170rpx; background-color: #eeeeee"
  7. :src="`${$imgUrl}applyCard/product-bg.png`"></image>
  8. <view class="item-value">
  9. <image class="icon-tip" :src="`${$imgUrl}applyCard/wechat.png`"></image>
  10. <view class="content">
  11. <view class="title"> {{state.detailsObj.productName}} </view>
  12. <view style="margin-top: 15rpx" class="tip"> {{state.detailsObj.releaseProduct.remarks}} </view>
  13. </view>
  14. <view class="price">
  15. ¥:{{state.detailsObj.product.oncePrice * 0.01}}
  16. </view>
  17. </view>
  18. </view>
  19. 加购权益列表
  20. <view class="add_all">
  21. <uni-swipe-action>
  22. <uni-swipe-action-item class="del_item" v-for="(item,index) in state.list"
  23. :right-options="state.options2" :show="item.isOpened" :auto-close="false" @change="change"
  24. @click="bindClick(index)">
  25. <view class="content-box">
  26. <view v-if='item.children' style="display: inline-block;">
  27. <image :class="item.isShow?'imageChange':'imageDefault'" @click="changeIsShow(index)"
  28. src="../../static/image/icon-back.png" alt="" srcset=""></image>
  29. </view>
  30. <text class="content-text" @tap="setOpened">{{item.productName}}
  31. &nbsp;¥{{item.discountPrice * 0.01}}</text>
  32. <view v-if="item.isShow" class="children" v-for="(itemChild,index) in item.children"
  33. :key='index'>
  34. <view>
  35. <text>{{itemChild.productName}}</text>&nbsp;&nbsp;<text>{{itemChild.discountPrice * 0.01}}</text>
  36. </view>
  37. </view>
  38. </view>
  39. </uni-swipe-action-item>
  40. </uni-swipe-action>
  41. </view>
  42. <view class="value-wrapper">
  43. <view class="flex">
  44. <view class="title"> 产品金额 </view>
  45. <view class="value">
  46. {{ "¥" + state.detailsObj.product.oncePrice * 0.01 }}
  47. </view>
  48. </view>
  49. <view class="flex">
  50. <view class="title"> 加购权益 </view>
  51. <view class="value">{{ "¥" + state.productMoney }} </view>
  52. </view>
  53. <view class="flex">
  54. <view class="title"> 运费 </view>
  55. <view class="value"> ¥0.00 </view>
  56. </view>
  57. <view class="flex">
  58. <view class="title"> 优惠券 </view>
  59. <view class="value"> 暂无优惠券 </view>
  60. </view>
  61. <view class="flex">
  62. <view class="title"> 积分兑换 </view>
  63. <view class="value"> 暂无积分 </view>
  64. </view>
  65. <view class="flex">
  66. <view class="title"> 实付款 </view>
  67. <view class="money">
  68. {{ "¥" + state.allMoney }}
  69. </view>
  70. </view>
  71. <!-- <view class="as-layout-horizontal as-gravity-center">
  72. <checkbox value="cb" />请先阅读并同意
  73. <a style="color:#007AFF;text-decoration: underline;">《ETC客户协议》</a>
  74. </view> -->
  75. </view>
  76. <view class="action">
  77. <button type="default" class="button" @click="savaHandle()">
  78. {{ "确认办理:¥" + state.allMoney }}
  79. </button>
  80. </view>
  81. </view>
  82. </template>
  83. <script setup lang="ts">
  84. import {
  85. onLoad,
  86. onShow
  87. } from "@dcloudio/uni-app";
  88. import {
  89. reactive,
  90. ref
  91. } from "vue";
  92. import {
  93. etcQueryProduct,
  94. addProduct
  95. } from "@/utils/network/api.js";
  96. import {
  97. request
  98. } from "@/utils/network/request.js";
  99. import {
  100. stringToJson
  101. } from "@/utils/network/encryption";
  102. import {
  103. fileURL
  104. } from "@/datas/fileURL.js";
  105. import navBgCar from "./components/nav-bg-car5";
  106. import navBar from "@/components/nav-bar/nav-bar2.vue";
  107. import {
  108. getItem,
  109. StorageKeys
  110. } from "@/utils/storage.ts";
  111. import {
  112. checkOrderStatus,
  113. orderPay,
  114. wechatAppID,
  115. wechatPayConfigId,
  116. wechatSecret,
  117. queryDetails
  118. } from "@/utils/network/api";
  119. import {
  120. confirm,
  121. msg
  122. } from "@/utils/utils";
  123. const imgURL = `${fileURL}image/`;
  124. const savaHandle = () => {
  125. console.log("state.productId.length", state.productId.length)
  126. //判断是否有加购权益
  127. if (state.productId.length > 0) {
  128. queryAddProduct();
  129. }
  130. uni.showModal({
  131. // title: '提示',
  132. content: '确定支付',
  133. success: function(res) {
  134. if (res.confirm) {
  135. console.log('用户点击确定');
  136. wxPayment();
  137. } else if (res.cancel) {
  138. console.log('用户点击取消');
  139. }
  140. }
  141. });
  142. // msg("确定绑定权益产品");
  143. // wxPayment();
  144. };
  145. //获取微信小程序openid
  146. const getOpenID = () => {
  147. uni.login({
  148. provider: "weixin",
  149. success: function(e) {
  150. wx.request({
  151. url: `https://api.weixin.qq.com/sns/jscode2session?appid=${wechatAppID}&secret=${wechatSecret}&js_code=${e.code}&grant_type=authorization_code`,
  152. success: (res: any) => {
  153. state.openid = res.data.openid;
  154. console.log("state.openid", state.openid);
  155. },
  156. });
  157. },
  158. });
  159. };
  160. //唤起微信支付
  161. const wxPayment = () => {
  162. // #ifdef MP-WEIXIN
  163. const options = {
  164. type: 2,
  165. data: {
  166. openid: state.openid,
  167. productId: state.id,
  168. orderId: state.orderId,
  169. payConfigId: wechatPayConfigId,
  170. },
  171. method: "POST",
  172. showLoading: true,
  173. };
  174. request(orderPay, options).then((res) => {
  175. const data = stringToJson(res.bizContent);
  176. uni.requestPayment({
  177. provider: "wxpay",
  178. orderInfo: "",
  179. timeStamp: data.timestamp,
  180. nonceStr: data.noncestr,
  181. package: data.wxPackage ?? "",
  182. signType: data.signType,
  183. paySign: data.sign,
  184. success: function(e) {
  185. console.log("支付成功", e);
  186. checkOrder();
  187. },
  188. fail: function(err) {
  189. // checkOrder();
  190. confirm(err, () => {}, "支付失败", false);
  191. },
  192. });
  193. });
  194. // #endif
  195. };
  196. //支付成功改变订单状态
  197. const checkOrder = () => {
  198. const options = {
  199. type: 2,
  200. data: {
  201. orderId: state.orderId,
  202. payConfigId: wechatPayConfigId,
  203. },
  204. method: "POST",
  205. showLoading: true,
  206. };
  207. request(checkOrderStatus, options).then((res) => {
  208. msg("支付成功!");
  209. var pages = getCurrentPages().length;
  210. uni.$emit("refreshOrder");
  211. uni.switchTab({
  212. url: "/pages/order/order"
  213. })
  214. });
  215. };
  216. onLoad((option: any) => {
  217. state.orderId = option.orderId;
  218. // state.clientFee = option.clientFee / 100;
  219. state.id = option.id;
  220. getOpenID();
  221. const data = JSON.parse(decodeURIComponent(option.data));
  222. for (var i = 0; i < data.length; i++) {
  223. data['isOpened'] = 'node';
  224. state.productMoney += data[i]['discountPrice'] / 100;
  225. state.productId.push(data[i]['equityId'])
  226. }
  227. state.list = data;
  228. queryDetailsData();
  229. });
  230. const state = reactive({
  231. openid: "",
  232. orderId: "",
  233. clientFee: undefined,
  234. id: "",
  235. options2: [{
  236. text: '删除',
  237. style: {
  238. backgroundColor: '#F56C6C'
  239. }
  240. }],
  241. isOpened: 'none',
  242. list: [],
  243. productMoney: 0,
  244. allMoney: 0,
  245. productId: [],
  246. // 弹框
  247. type: 'center',
  248. msgType: 'success',
  249. messageText: '这是一条成功提示',
  250. value: '',
  251. detailsObj: '',
  252. });
  253. const bindClick = (i) => {
  254. console.log(i);
  255. uni.showToast({
  256. title: "删除成功",
  257. icon: 'none'
  258. });
  259. state.list.splice(i, 1);
  260. state.productMoney = 0;
  261. state.productId = [];
  262. for (var k = 0; k < state.list.length; k++) {
  263. state.productMoney += state.list[k]['discountPrice'] / 100
  264. state.productId.push(state.list[k]['equityId'])
  265. }
  266. state.allMoney = (state.productMoney + state.clientFee).toFixed(2)
  267. console.log("state.productId", state.productId)
  268. };
  269. const setOpened = () => {
  270. if (state.isOpened === 'none') {
  271. state.isOpened = 'right';
  272. return;
  273. }
  274. if (state.isOpened === 'left') {
  275. state.isOpened = 'right';
  276. return;
  277. }
  278. if (state.isOpened === 'right') {
  279. state.isOpened = 'none';
  280. return;
  281. }
  282. }
  283. const change = (e) => {
  284. state.isOpened = e;
  285. }
  286. // 加购权益产品接口
  287. const queryAddProduct = () => {
  288. console.log("state.openid", state.openid);
  289. const options = {
  290. type: 2,
  291. data: {
  292. orderId: state.orderId, //订单编号
  293. openId: state.openid, //操作人 id
  294. equityId: state.productId.toString(), //权益Id
  295. totalAmount: state.allMoney * 100, //总金额
  296. isRepeatPurchase: 0
  297. },
  298. method: "POST",
  299. showLoading: true,
  300. };
  301. request(addProduct, options).then((res) => {});
  302. }
  303. const changeIsShow = (index) => {
  304. console.log(index, state.list[index]['isShow'], !state.list[index]['isShow'])
  305. state.list[index]['isShow'] = !state.list[index]['isShow']
  306. console.log("state.list", state.list)
  307. }
  308. const queryDetailsData = () => {
  309. const options = {
  310. type: 2,
  311. data: {
  312. orderId: state.orderId, //订单编号
  313. },
  314. method: "POST",
  315. showLoading: true,
  316. };
  317. request(queryDetails, options).then((res) => {
  318. state.detailsObj = stringToJson(res.bizContent);
  319. console.log("state.detailsObj",state.detailsObj)
  320. state.allMoney = (parseFloat(state.detailsObj.product.oncePrice * 0.01) + parseFloat(state.productMoney)).toFixed(2)
  321. });
  322. }
  323. </script>
  324. <style lang="scss" scoped>
  325. .action {
  326. margin-top: 40rpx;
  327. padding-left: 20rpx;
  328. padding-right: 20rpx;
  329. padding-bottom: 30rpx;
  330. .button {
  331. height: 80rpx;
  332. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  333. border-radius: 40rpx;
  334. font-size: 32rpx;
  335. font-weight: 400;
  336. color: #ffffff;
  337. line-height: 80rpx;
  338. }
  339. }
  340. .value-wrapper {
  341. margin-top: 40rpx;
  342. padding: 0rpx 30rpx;
  343. .flex {
  344. padding: 20rpx 0rpx;
  345. display: flex;
  346. justify-content: space-between;
  347. align-items: center;
  348. .title {
  349. font-size: 28rpx;
  350. font-family: Microsoft YaHei;
  351. font-weight: 400;
  352. color: #777777;
  353. line-height: 28rpx;
  354. }
  355. .value {
  356. font-size: 28rpx;
  357. font-family: Microsoft YaHei;
  358. font-weight: 400;
  359. color: #333333;
  360. line-height: 28rpx;
  361. }
  362. .money {
  363. font-size: 36rpx;
  364. font-family: Microsoft YaHei;
  365. font-weight: 400;
  366. color: #00b38b;
  367. line-height: 36rpx;
  368. }
  369. }
  370. }
  371. .content-wrap {
  372. position: relative;
  373. margin-top: -50rpx;
  374. padding: 0rpx 30rpx;
  375. .ul-item {
  376. padding: 5px 20rpx;
  377. display: flex;
  378. align-items: center;
  379. .item-value {
  380. padding: 20rpx;
  381. position: absolute;
  382. display: flex;
  383. align-items: center;
  384. // justify-content: space-around;
  385. width: 80%;
  386. .content {
  387. width: 48%;
  388. .title {
  389. font-size: 32rpx;
  390. font-family: Microsoft YaHei;
  391. font-weight: 400;
  392. color: #ffffff;
  393. }
  394. .tip {
  395. font-size: 24rpx;
  396. font-family: Microsoft YaHei;
  397. font-weight: 400;
  398. color: #ffffff;
  399. }
  400. }
  401. }
  402. .icon-tip {
  403. width: 100rpx;
  404. height: 100rpx;
  405. }
  406. .content {
  407. margin-left: 40rpx;
  408. }
  409. }
  410. }
  411. .del_item {
  412. background-color: rgb(41, 199, 207) !important;
  413. }
  414. .content-box {
  415. background-color: rgb(41, 199, 207);
  416. line-height: 80rpx;
  417. color: white;
  418. font-size: 32rpx;
  419. border-radius: 10rpx 0 0 10rpx;
  420. padding: 20rpx;
  421. box-sizing: border-box;
  422. }
  423. ::v-deep.uni-swipe_button-text {
  424. font-size: 30rpx !important;
  425. }
  426. ::v-deep.uni-swipe_button-group {
  427. font-size: 28rpx !important;
  428. }
  429. .add_all {
  430. width: 95%;
  431. margin: 0 auto;
  432. }
  433. .uni-swipe_box {
  434. margin-bottom: 16rpx !important;
  435. }
  436. ::v-deep.uni-swipe {
  437. margin-bottom: 16rpx !important;
  438. }
  439. .imageDefault {
  440. height: 40rpx;
  441. width: 40rpx;
  442. transform: rotate(270deg);
  443. margin-right: 12rpx;
  444. color: white;
  445. }
  446. .imageChange {
  447. height: 40rpx;
  448. width: 40rpx;
  449. transform: rotate(90deg);
  450. margin-right: 12rpx;
  451. color: white;
  452. }
  453. .price {
  454. color: white;
  455. }
  456. </style>