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 12KB

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