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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <view class="content">
  3. <view class="item" v-for="(item,index) in state.list" :key='index'>
  4. <view class="title" @click="addInterestsList(item)">
  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="addInterestsList()">
  24. 加购权益
  25. </button> -->
  26. </view>
  27. </template>
  28. <script setup lang="ts">
  29. import { onLoad, onShow } from "@dcloudio/uni-app";
  30. import { reactive } from "vue";
  31. import { equityProductsApi } from "@/utils/network/api.js";
  32. import { stringToJson } from "@/utils/network/encryption";
  33. import { request } from "@/utils/network/request";
  34. import { etcQYAction } from "@/utils/network/api.js";
  35. import { fileURL } from "@/datas/fileURL.js";
  36. import navBar from "@/components/nav-bar/nav-bar2.vue";
  37. import navBgCar from "./components/nav-bg-car4";
  38. // import { setItem } from "@/utils/storage";
  39. import { msg } from "@/utils/utils";
  40. import {
  41. checkOrderStatus,
  42. wechatAppID,
  43. wechatPayConfigId,
  44. wechatSecret,
  45. addProduct,
  46. queryDetails,
  47. getOpenidApi
  48. } from "@/utils/network/api";
  49. import {
  50. getItem,
  51. StorageKeys,
  52. setItem
  53. } from "@/utils/storage";
  54. const imgURL = `${fileURL}image/`;
  55. const state = reactive({
  56. openid: "",
  57. orderId: "",
  58. id: "",
  59. clientFee: "",
  60. list: [], //权益数据
  61. choiceValue: [], //选择的权益数据的下标
  62. choiceValueComplete: [], //选择的权益数据的具体数据
  63. isValueCard: "",
  64. type: 0,
  65. userType: 0,
  66. promoteId: "", //产品id
  67. totalAmount: 0, //产品+权益产品金额
  68. })
  69. onLoad((option : any) => {
  70. // getList("promoteId", option);
  71. console.log("promoteId", option)
  72. state.orderId = option.orderId;
  73. state.clientFee = option.clientFee;
  74. state.id = option.id;
  75. state.userType = option.userType;
  76. state.type = option.type;
  77. state.isValueCard = option.isValueCard;
  78. state.promoteId = option.promoteId;
  79. state.totalAmount = option.fee;
  80. getList();
  81. getOpenID();
  82. console.log("option", option)
  83. })
  84. const addInterestsList = (item) => {
  85. console.log("item", item)
  86. state.totalAmount = Number(state.totalAmount) + Number(item.discountPrice)
  87. uni.redirectTo({
  88. url: `/subpackage/orders/essential-information?promoteId=${getItem("promoteId")}&userType=${state.userType}&type=${state.type}&isValueCard=${state.isValueCard}&totalAmount=${state.totalAmount}&equityId=${item.equityId}`,
  89. });
  90. return;
  91. state.choiceValueComplete = [];
  92. for (var i = 0; i < state.choiceValue.length; i++) {
  93. state.choiceValueComplete.push(state.list[state.choiceValue[i]])
  94. }
  95. let items = encodeURIComponent(JSON.stringify(state.choiceValueComplete));
  96. console.log("state.openid", state);
  97. const data = JSON.parse(decodeURIComponent(items));
  98. let productId = [];
  99. state.productMoney = 0;
  100. for (var i = 0; i < data.length; i++) {
  101. data['isOpened'] = 'node';
  102. state.productMoney += data[i]['discountPrice'] / 100;
  103. productId.push(data[i]['equityId'])
  104. }
  105. const options = {
  106. type: 2,
  107. data: {
  108. orderId: state.orderId, //订单编号
  109. },
  110. method: "POST",
  111. showLoading: true,
  112. };
  113. console.log("options", options);
  114. request(queryDetails, options).then((res) => {
  115. state.detailsObj = stringToJson(res.bizContent);
  116. console.log("state.detailsObj", state.detailsObj)
  117. let allMoney = (parseFloat(state.detailsObj.product.oncePrice * 0.01) + parseFloat(state.productMoney)).toFixed(2)
  118. const optionss = {
  119. type: 2,
  120. data: {
  121. orderId: state.orderId, //订单编号
  122. openId: getItem(StorageKeys.OpenId), //操作人 id
  123. equityId: productId.toString(), //权益Id
  124. totalAmount: allMoney * 100, //总金额
  125. isRepeatPurchase: 0
  126. },
  127. method: "POST",
  128. showLoading: true,
  129. };
  130. console.log("optionss", optionss);
  131. request(addProduct, optionss).then((res) => {
  132. // uni.redirectTo({
  133. // url: `/subpackage/orders/product-detail?orderId=${state.orderId}&&clientFee=${state.clientFee}&&id=${state.id}&&data=${items}&&isValueCard=${state.detailsObj.isValueCard}`,
  134. // });
  135. uni.redirectTo({
  136. url: `/subpackage/orders/essential-information?promoteId=${getItem("promoteId")}&userType=${state.userType}&type=${state.type}&isValueCard=${state.isValueCard}`,
  137. });
  138. });
  139. });
  140. }
  141. const getList = () => {
  142. const options = {
  143. type: 2,
  144. data: {
  145. "promoteId": state.promoteId,
  146. },
  147. method: 'POST',
  148. showLoading: true,
  149. }
  150. request(equityProductsApi, options).then((res) => {
  151. const data = stringToJson(res.bizContent);
  152. for (var i = 0; i < data.data.length; i++) {
  153. data.data[i]['isShow'] = false;
  154. }
  155. state.list = data.data
  156. console.log("222", data.data)
  157. })
  158. }
  159. const change = (e) => {
  160. console.log(e);
  161. }
  162. //获取微信小程序openid
  163. const getOpenID = () => {
  164. // #ifdef MP-WEIXIN
  165. uni.login({
  166. provider: "weixin",
  167. success: function (e) {
  168. console.log(e);
  169. getOpenid(e.code);
  170. },
  171. });
  172. //#endif
  173. };
  174. const getOpenid = (code) => {
  175. const options = {
  176. type: 2,
  177. data: {
  178. "jsCode": code
  179. },
  180. method: "POST",
  181. showLoading: true,
  182. };
  183. // #ifdef MP-WEIXIN
  184. request(getOpenidApi, options).then((res) => {
  185. const result = stringToJson(res.bizContent);
  186. console.log("获取微信小程序openid", result);
  187. const openidData = stringToJson(result.data);
  188. state.openid = openidData.openid;
  189. setItem("QYorder", state);
  190. // setItem("QYorder", result.data);
  191. // state.openid = result.data.openid
  192. });
  193. // #endif
  194. }
  195. const changeIsShow = (index) => {
  196. console.log(index, state.list[index]['isShow'], !state.list[index]['isShow'])
  197. state.list[index]['isShow'] = !state.list[index]['isShow']
  198. console.log("state.list", state.list)
  199. }
  200. const getValue = (value) => {
  201. if (state.choiceValue.length == 0) {
  202. console.log("第一次")
  203. state.choiceValue.push(value)
  204. console.log("state.choiceValue", state.choiceValue)
  205. } else {
  206. var index = state.choiceValue.indexOf(value);
  207. if (index > -1) {//大于0 代表存在,
  208. state.choiceValue.splice(index, 1);//存在就删除
  209. } else {
  210. state.choiceValue.push(value)
  211. }
  212. console.log("state.choiceValue", state.choiceValue)
  213. }
  214. }
  215. </script>
  216. <style scoped lang="scss">
  217. .content {
  218. width: 100%;
  219. height: 100vh;
  220. }
  221. .button {
  222. height: 80rpx;
  223. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  224. border-radius: 40rpx;
  225. font-size: 32rpx;
  226. font-weight: 400;
  227. color: #ffffff;
  228. line-height: 80rpx;
  229. margin: 20rpx;
  230. }
  231. .imageDefault {
  232. height: 40rpx;
  233. width: 40rpx;
  234. transform: rotate(270deg);
  235. margin-right: 12rpx;
  236. color: white;
  237. }
  238. .imageChange {
  239. height: 40rpx;
  240. width: 40rpx;
  241. transform: rotate(90deg);
  242. margin-right: 12rpx;
  243. color: white;
  244. }
  245. .item {
  246. width: 90%;
  247. margin: 20rpx auto;
  248. background-color: rgb(41, 199, 207);
  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>