Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

product-detail.vue 10KB

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