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

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