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.

interestsList.vue 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. s<template>
  2. <view class="content">
  3. <view class="item" v-for="(item,index) in state.list" :key='index'>
  4. <view class="title">
  5. <view>
  6. <view v-if='item.children' style="display: inline-block;">
  7. <image :class="item.isShow?'imageChange':'imageDefault'" @click="changeIsShow(index)"
  8. src="../../static/image/icon-back.png" alt="" srcset=""></image>
  9. </view>
  10. <text><text>{{item.productName}}</text>&nbsp;&nbsp;<text>¥{{item.discountPrice * 0.01}}</text></text>
  11. </view>
  12. <checkbox-group @change='getValue(index)'>
  13. <label>
  14. <checkbox :value="index" />
  15. </label>
  16. </checkbox-group>
  17. </view>
  18. <view v-if="item.isShow" class="children" v-for="(itemChild,index) in item.children" :key='index'>
  19. <view><text>{{itemChild.productName}}</text>&nbsp;&nbsp;<text>{{itemChild.discountPrice * 0.01}}</text>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- <button type="default" class="button" @click="savaHandle()">
  24. 开通服务
  25. </button> -->
  26. <button type="default" class="button" @click="addInterestsList()">
  27. 加购权益
  28. </button>
  29. </view>
  30. </template>
  31. <script setup lang="ts">
  32. import { onLoad, onShow } from "@dcloudio/uni-app";
  33. import { reactive } from "vue";
  34. import { queryInterestsList } from "@/utils/network/api.js";
  35. import { stringToJson } from "@/utils/network/encryption";
  36. import { request } from "@/utils/network/request";
  37. import { etcQYAction } from "@/utils/network/api.js";
  38. import { fileURL } from "@/datas/fileURL.js";
  39. import navBar from "@/components/nav-bar/nav-bar2.vue";
  40. import navBgCar from "./components/nav-bg-car4";
  41. // import { setItem } from "@/utils/storage";
  42. import { msg } from "@/utils/utils";
  43. import {
  44. checkOrderStatus,
  45. orderPay,
  46. wechatAppID,
  47. wechatPayConfigId,
  48. wechatSecret,
  49. addProduct,
  50. queryDetails,
  51. getOpenidApi
  52. } from "@/utils/network/api";
  53. import {
  54. getItem,
  55. StorageKeys,
  56. setItem
  57. } from "@/utils/storage";
  58. const imgURL = `${fileURL}image/`;
  59. const state = reactive({
  60. openid: "",
  61. orderId: "",
  62. id: "",
  63. clientFee: "",
  64. list: [], //权益数据
  65. choiceValue: [], //选择的权益数据的下标
  66. choiceValueComplete: [] //选择的权益数据的具体数据
  67. })
  68. onLoad((option : any) => {
  69. getList(option.orderId);
  70. getOpenID();
  71. state.orderId = option.orderId;
  72. state.clientFee = option.clientFee;
  73. state.id = option.id;
  74. console.log("option", option)
  75. })
  76. const addInterestsList = () => {
  77. state.choiceValueComplete = [];
  78. for (var i = 0; i < state.choiceValue.length; i++) {
  79. state.choiceValueComplete.push(state.list[state.choiceValue[i]])
  80. }
  81. let items = encodeURIComponent(JSON.stringify(state.choiceValueComplete));
  82. console.log("state.openid", state);
  83. const data = JSON.parse(decodeURIComponent(items));
  84. let productId = [];
  85. state.productMoney = 0;
  86. for (var i = 0; i < data.length; i++) {
  87. data['isOpened'] = 'node';
  88. state.productMoney += data[i]['discountPrice'] / 100;
  89. productId.push(data[i]['equityId'])
  90. }
  91. const options = {
  92. type: 2,
  93. data: {
  94. orderId: state.orderId, //订单编号
  95. },
  96. method: "POST",
  97. showLoading: true,
  98. };
  99. console.log("options", options);
  100. request(queryDetails, options).then((res) => {
  101. state.detailsObj = stringToJson(res.bizContent);
  102. console.log("state.detailsObj", state.detailsObj)
  103. let allMoney = (parseFloat(state.detailsObj.product.oncePrice * 0.01) + parseFloat(state.productMoney)).toFixed(2)
  104. const optionss = {
  105. type: 2,
  106. data: {
  107. orderId: state.orderId, //订单编号
  108. openId: getItem(StorageKeys.OpenId), //操作人 id
  109. equityId: productId.toString(), //权益Id
  110. totalAmount: allMoney * 100, //总金额
  111. isRepeatPurchase: 0
  112. },
  113. method: "POST",
  114. showLoading: true,
  115. };
  116. console.log("optionss", optionss);
  117. request(addProduct, optionss).then((res) => {
  118. uni.navigateTo({
  119. url: `/subpackage/orders/order_payment?orderId=${state.orderId}&&clientFee=${state.clientFee}&&id=${state.id}&&data=${items}`,
  120. });
  121. });
  122. });
  123. }
  124. const getList = (id) => {
  125. const options = {
  126. type: 2,
  127. data: { "orderId": id },
  128. method: 'POST',
  129. showLoading: true,
  130. }
  131. request(queryInterestsList, options).then((res) => {
  132. const data = stringToJson(res.bizContent);
  133. for (var i = 0; i < data.data.length; i++) {
  134. data.data[i]['isShow'] = false;
  135. }
  136. state.list = data.data
  137. console.log("222", state.list)
  138. })
  139. }
  140. const change = (e) => {
  141. console.log(e);
  142. }
  143. //获取微信小程序openid
  144. const getOpenID = () => {
  145. // #ifdef MP-WEIXIN
  146. uni.login({
  147. provider: "weixin",
  148. success: function (e) {
  149. console.log(e);
  150. getOpenid(e.code);
  151. // uni.request({
  152. // url: `https://api.weixin.qq.com/sns/jscode2session?appid=${wechatAppID}&secret=${wechatSecret}&js_code=${e.code}&grant_type=authorization_code`,
  153. // success: (res : any) => {
  154. // state.openid = res.data.openid;
  155. // setItem("QYorder", state);
  156. // console.log(res);
  157. // },
  158. // fail: (err : any) => {
  159. // uni.showToast({
  160. // title: "网络异常,请重试!" + err.errcode,
  161. // icon: "error",
  162. // duration: 500,
  163. // });
  164. // return;
  165. // },
  166. // });
  167. },
  168. });
  169. //#endif
  170. };
  171. const getOpenid = (code) => {
  172. const options = {
  173. type: 2,
  174. data: {
  175. "jsCode": code
  176. },
  177. method: "POST",
  178. showLoading: true,
  179. };
  180. // #ifdef MP-WEIXIN
  181. request(getOpenidApi, options).then((res) => {
  182. const result = stringToJson(res.bizContent);
  183. console.log("获取微信小程序openid", result);
  184. state.openid = result.data.openid;
  185. setItem("QYorder", state);
  186. // setItem("QYorder", result.data);
  187. // state.openid = result.data.openid
  188. });
  189. // #endif
  190. }
  191. const savaHandle = () => {
  192. state.choiceValueComplete = [];
  193. for (var i = 0; i < state.choiceValue.length; i++) {
  194. state.choiceValueComplete.push(state.list[state.choiceValue[i]])
  195. }
  196. let items = encodeURIComponent(JSON.stringify(state.choiceValueComplete));
  197. console.log("state.choiceValueComplete", state.choiceValueComplete)
  198. console.log("openid*******", state.openid);
  199. //如果获取openId成功
  200. if (state.openid) {
  201. var data = {
  202. orderId: state.orderId,
  203. subOpenId: state.openid,
  204. };
  205. const options = {
  206. type: 2,
  207. data: data,
  208. method: "POST",
  209. showLoading: true,
  210. };
  211. request(etcQYAction, options).then((res) => {
  212. const data = stringToJson(res.bizContent);
  213. if (data.userState === "UNAUTHORIZED") {
  214. uni.navigateToMiniProgram({
  215. appId: "wxbcad394b3d99dac9",
  216. path: "pages/route/index",
  217. extraData: {
  218. appid: "wxcb1388c809fe25a9",
  219. sub_appid: "wx008c60533388527a",
  220. mch_id: "1500877591",
  221. sub_mch_id: "1622652848",
  222. nonce_str: data.nonceStr,
  223. sign_type: "HMAC-SHA256",
  224. trade_scene: "HIGHWAY",
  225. plate_number: data.plateNumber,
  226. sub_openid: data.subOpenId,
  227. sign: data.sign,
  228. },
  229. success(res) {
  230. console.log(res);
  231. },
  232. complete(res) {
  233. console.log(res);
  234. },
  235. fail(res) {
  236. console.log(res);
  237. // 未成功跳转到车主小程序
  238. },
  239. });
  240. } else if (data.userState === "NORMAL") {
  241. msg("已开通车主服务");
  242. uni.navigateTo({
  243. url: `/subpackage/orders/product-detail?orderId=${state.orderId}&&clientFee=${state.clientFee}&&id=${state.id}&&data=${items}`,
  244. });
  245. } else if (data.userState === "PAUSED") {
  246. msg("已暂停车主服务");
  247. return;
  248. } else if (data.userState === "OVERDUE") {
  249. msg("用户已开通车主服务,但欠费状态。提示用户还款,请跳转到车主服务");
  250. return;
  251. }
  252. });
  253. } else {
  254. //如果获取openId失败
  255. uni.showToast({
  256. title: "网络异常,请重试!",
  257. icon: "none",
  258. duration: 1000,
  259. });
  260. return;
  261. }
  262. };
  263. const changeIsShow = (index) => {
  264. console.log(index, state.list[index]['isShow'], !state.list[index]['isShow'])
  265. state.list[index]['isShow'] = !state.list[index]['isShow']
  266. console.log("state.list", state.list)
  267. }
  268. const getValue = (value) => {
  269. if (state.choiceValue.length == 0) {
  270. console.log("第一次")
  271. state.choiceValue.push(value)
  272. console.log("state.choiceValue", state.choiceValue)
  273. } else {
  274. var index = state.choiceValue.indexOf(value);
  275. if (index > -1) {//大于0 代表存在,
  276. state.choiceValue.splice(index, 1);//存在就删除
  277. } else {
  278. state.choiceValue.push(value)
  279. }
  280. console.log("state.choiceValue", state.choiceValue)
  281. }
  282. }
  283. </script>
  284. <style scoped lang="scss">
  285. .content {
  286. width: 100%;
  287. height: 100vh;
  288. }
  289. .button {
  290. height: 80rpx;
  291. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  292. border-radius: 40rpx;
  293. font-size: 32rpx;
  294. font-weight: 400;
  295. color: #ffffff;
  296. line-height: 80rpx;
  297. margin: 20rpx;
  298. }
  299. .imageDefault {
  300. height: 40rpx;
  301. width: 40rpx;
  302. transform: rotate(270deg);
  303. margin-right: 12rpx;
  304. color: white;
  305. }
  306. .imageChange {
  307. height: 40rpx;
  308. width: 40rpx;
  309. transform: rotate(90deg);
  310. margin-right: 12rpx;
  311. color: white;
  312. }
  313. .item {
  314. width: 90%;
  315. margin: 10rpx auto;
  316. background-color: rgb(41, 199, 207);
  317. // height: 150rpx;
  318. border-radius: 20rpx;
  319. padding: 20rpx;
  320. box-sizing: border-box;
  321. color: white;
  322. font-size: 32rpx;
  323. }
  324. .item>.title {
  325. width: 100%;
  326. display: flex;
  327. justify-content: space-between;
  328. align-items: center;
  329. }
  330. .title>checkbox-group {
  331. // float: right;
  332. }
  333. .children {
  334. margin-left: 50rpx;
  335. margin-top: 16rpx;
  336. }
  337. .children>view {
  338. height: 50rpx;
  339. line-height: 50rpx;
  340. }
  341. .show {
  342. display: inline-block;
  343. }
  344. .hide {
  345. display: none;
  346. }
  347. checkbox {
  348. transform: scale(0.8);
  349. }
  350. </style>