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

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