您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

interestsList.vue 8.9KB

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