Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

product-detail.vue 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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
  23. class="del_item"
  24. v-for="(item,index) in state.list"
  25. :right-options="state.options2"
  26. :show="item.isOpened"
  27. :auto-close="false"
  28. @change="change"
  29. @click="bindClick(index)"
  30. >
  31. <view class="content-box">
  32. <view v-if='item.children' style="display: inline-block;">
  33. <image :class="item.isShow?'imageChange':'imageDefault'" @click="changeIsShow(index)" src="../../static/image/icon-back.png" alt="" srcset=""></image>
  34. </view>
  35. <text class="content-text" @tap="setOpened">{{item.productName}} &nbsp;¥{{item.discountPrice * 0.01}}</text>
  36. <view v-if="item.isShow" class="children" v-for="(itemChild,index) in item.children" :key='index'>
  37. <view><text>{{itemChild.productName}}</text>&nbsp;&nbsp;<text>{{itemChild.discountPrice * 0.01}}</text></view>
  38. </view>
  39. </view>
  40. </uni-swipe-action-item>
  41. </uni-swipe-action>
  42. </view>
  43. <view class="value-wrapper">
  44. <view class="flex">
  45. <view class="title"> 产品金额 </view>
  46. <view class="value">
  47. {{ "¥" + state.clientFee }}
  48. </view>
  49. </view>
  50. <view class="flex">
  51. <view class="title"> 加购权益 </view>
  52. <view class="value">{{ "¥" + state.productMoney }} </view>
  53. </view>
  54. <view class="flex">
  55. <view class="title"> 运费 </view>
  56. <view class="value"> ¥0.00 </view>
  57. </view>
  58. <view class="flex">
  59. <view class="title"> 优惠券 </view>
  60. <view class="value"> 暂无优惠券 </view>
  61. </view>
  62. <view class="flex">
  63. <view class="title"> 积分兑换 </view>
  64. <view class="value"> 暂无积分 </view>
  65. </view>
  66. <view class="flex">
  67. <view class="title"> 实付款 </view>
  68. <view class="money">
  69. {{ "¥" + state.allMoney }}
  70. </view>
  71. </view>
  72. </view>
  73. <view class="action">
  74. <button type="default" class="button" @click="savaHandle()">
  75. {{ "确认办理:¥" + state.allMoney }}
  76. </button>
  77. </view>
  78. </view>
  79. </template>
  80. <script setup lang="ts">
  81. import {
  82. onLoad,
  83. onShow
  84. } from "@dcloudio/uni-app";
  85. import {
  86. reactive,ref
  87. } from "vue";
  88. import {
  89. etcQueryProduct,addProduct
  90. } from "@/utils/network/api.js";
  91. import {
  92. request
  93. } from "@/utils/network/request.js";
  94. import {
  95. stringToJson
  96. } from "@/utils/network/encryption";
  97. import {
  98. fileURL
  99. } from "@/datas/fileURL.js";
  100. import navBgCar from "./components/nav-bg-car5";
  101. import navBar from "@/components/nav-bar/nav-bar2.vue";
  102. import {
  103. getItem,
  104. StorageKeys
  105. } from "@/utils/storage.ts";
  106. import {
  107. checkOrderStatus,
  108. orderPay,
  109. wechatAppID,
  110. wechatPayConfigId,
  111. wechatSecret,
  112. queryDetails
  113. } from "@/utils/network/api";
  114. import {
  115. confirm,
  116. msg
  117. } from "@/utils/utils";
  118. const imgURL = `${fileURL}image/`;
  119. const savaHandle = () => {
  120. console.log("state.productId.length",state.productId.length)
  121. if(state.productId.length>0){
  122. queryAddProduct();
  123. uni.showModal({
  124. // title: '提示',
  125. content: '确定支付',
  126. success: function (res) {
  127. if (res.confirm) {
  128. console.log('用户点击确定');
  129. wxPayment();
  130. } else if (res.cancel) {
  131. console.log('用户点击取消');
  132. }
  133. }
  134. });
  135. }else{
  136. wxPayment();
  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.allMoney=(state.productMoney+state.clientFee).toFixed(2)
  224. state.list=data;
  225. console.log("data",option)
  226. console.log("数组",JSON.parse(decodeURIComponent(option.data)))
  227. queryDetailsData();
  228. });
  229. const state = reactive({
  230. openid: "",
  231. orderId: "",
  232. clientFee: undefined,
  233. id: "",
  234. options2: [{
  235. text: '删除',
  236. style: {
  237. backgroundColor: '#F56C6C'
  238. }
  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. console.log('返回:', e);
  286. }
  287. // 加购权益产品接口
  288. const queryAddProduct=()=>{
  289. console.log("state.openid",state.openid);
  290. const options = {
  291. type: 2,
  292. data: {
  293. orderId: state.orderId, //订单编号
  294. openId: state.openid, //操作人 id
  295. equityId: state.productId.toString() , //权益Id
  296. totalAmount: state.allMoney * 100, //总金额
  297. isRepeatPurchase:0
  298. },
  299. method: "POST",
  300. showLoading: true,
  301. };
  302. request(addProduct, options).then((res) => {
  303. // msg("加购权益成功。");
  304. });
  305. }
  306. const changeIsShow = (index) =>{
  307. console.log(index,state.list[index]['isShow'],!state.list[index]['isShow'])
  308. state.list[index]['isShow']=!state.list[index]['isShow']
  309. console.log("state.list",state.list)
  310. }
  311. const queryDetailsData=()=>{
  312. const options = {
  313. type: 2,
  314. data: {
  315. orderId: state.orderId, //订单编号
  316. },
  317. method: "POST",
  318. showLoading: true,
  319. };
  320. request(queryDetails, options).then((res) => {
  321. state.detailsObj=stringToJson(res.bizContent);
  322. console.log("sdd",stringToJson(res.bizContent))
  323. });
  324. }
  325. </script>
  326. <style lang="scss" scoped>
  327. .action {
  328. margin-top: 40rpx;
  329. padding-left: 20rpx;
  330. padding-right: 20rpx;
  331. padding-bottom: 30rpx;
  332. .button {
  333. height: 80rpx;
  334. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  335. border-radius: 40rpx;
  336. font-size: 32rpx;
  337. font-weight: 400;
  338. color: #ffffff;
  339. line-height: 80rpx;
  340. }
  341. }
  342. .value-wrapper {
  343. margin-top: 40rpx;
  344. padding: 0rpx 30rpx;
  345. .flex {
  346. padding: 20rpx 0rpx;
  347. display: flex;
  348. justify-content: space-between;
  349. align-items: center;
  350. .title {
  351. font-size: 28rpx;
  352. font-family: Microsoft YaHei;
  353. font-weight: 400;
  354. color: #777777;
  355. line-height: 28rpx;
  356. }
  357. .value {
  358. font-size: 28rpx;
  359. font-family: Microsoft YaHei;
  360. font-weight: 400;
  361. color: #333333;
  362. line-height: 28rpx;
  363. }
  364. .money {
  365. font-size: 36rpx;
  366. font-family: Microsoft YaHei;
  367. font-weight: 400;
  368. color: #00b38b;
  369. line-height: 36rpx;
  370. }
  371. }
  372. }
  373. .content-wrap {
  374. position: relative;
  375. margin-top: -50rpx;
  376. padding: 0rpx 30rpx;
  377. .ul-item {
  378. padding: 5px 20rpx;
  379. display: flex;
  380. align-items: center;
  381. .item-value {
  382. padding: 20rpx;
  383. position: absolute;
  384. display: flex;
  385. align-items: center;
  386. // justify-content: space-around;
  387. width: 80%;
  388. .content {
  389. width: 48%;
  390. .title {
  391. font-size: 32rpx;
  392. font-family: Microsoft YaHei;
  393. font-weight: 400;
  394. color: #ffffff;
  395. }
  396. .tip {
  397. font-size: 24rpx;
  398. font-family: Microsoft YaHei;
  399. font-weight: 400;
  400. color: #ffffff;
  401. }
  402. }
  403. }
  404. .icon-tip {
  405. width: 100rpx;
  406. height: 100rpx;
  407. }
  408. .content {
  409. margin-left: 40rpx;
  410. }
  411. }
  412. }
  413. .del_item{
  414. background-color: rgb(41, 199, 207) !important;
  415. }
  416. .content-box{
  417. background-color: rgb(41, 199, 207);
  418. line-height: 80rpx;
  419. color: white;
  420. font-size: 32rpx;
  421. border-radius: 10rpx 0 0 10rpx;
  422. padding: 20rpx;
  423. box-sizing: border-box;
  424. }
  425. ::v-deep.uni-swipe_button-text{
  426. font-size: 30rpx !important;
  427. }
  428. ::v-deep.uni-swipe_button-group {
  429. font-size: 28rpx !important;
  430. }
  431. .add_all{
  432. width: 95%;
  433. margin: 0 auto;
  434. }
  435. .uni-swipe_box{
  436. margin-bottom: 16rpx !important;
  437. }
  438. ::v-deep.uni-swipe {
  439. margin-bottom: 16rpx !important;
  440. }
  441. .imageDefault{
  442. height: 40rpx;
  443. width: 40rpx;
  444. transform: rotate(270deg);
  445. margin-right: 12rpx;
  446. color: white;
  447. }
  448. .imageChange{
  449. height: 40rpx;
  450. width: 40rpx;
  451. transform: rotate(90deg);
  452. margin-right: 12rpx;
  453. color: white;
  454. }
  455. .price{
  456. color: white;
  457. }
  458. </style>