goodsDetail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <!--
  2. [商品兑换] 样式1 - 商品详情
  3. http://localhost:5173/card/#/pages/exchange/style1/goodsDetail
  4. https://oss-mbh5.colormaprun.com/card/#/pages/exchange/style1/goodsDetail
  5. -->
  6. <template>
  7. <view class="body">
  8. <view v-if="pageReady" class="content uni-column">
  9. <view class="uni-column exchg-top">
  10. <my-topbar :exchangeTitle="exchangeTitle" ruleLable="兑换地点" class="exchgbar-color" @btnBackClick="btnBack"
  11. @btnInfoClick="btnInfo"></my-topbar>
  12. <view class="top-content">
  13. <view class="scoreBox uni-row uni-jcsb">
  14. <view class="scoreBox-score uni-row">
  15. <view class="scoreBox-title">剩余积分</view>
  16. <image class="scoreBox-score-ico" mode="aspectFit" src="/static/exchange/score.png"></image>
  17. <view class="scoreBox-score-value">{{scoreRs.score}}</view>
  18. </view>
  19. <view class="scoreBox-expire">{{fmtTime(scoreRs.extTime)}} 到期</view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="main uni-column">
  24. <view class="goodsBox uni-column">
  25. <view class="goods-title">{{goodsRs.goodsName}}</view>
  26. <image class="goods-pic" mode="aspectFit" :src="goodsRs.goodsPic"></image>
  27. <view class="goods-priceBox uni-row uni-jcsb">
  28. <view class="goods-priceBox-text uni-row">库存 {{goodsRs.goodsLeftNum}}<view v-if="goodsRs.goodsUnit.length > 0">{{goodsRs.goodsUnit}}</view></view>
  29. <view class="uni-row">
  30. <image class="goods-scoreIco" mode="aspectFit" src="/static/exchange/score2.png"></image>
  31. <view class="goods-priceBox-text uni-row">{{goodsRs.corrScore}}积分<view v-if="goodsRs.goodsUnit.length > 0">/{{goodsRs.goodsUnit}}</view></view>
  32. </view>
  33. </view>
  34. <view class="goods-exchNumBox">
  35. <uni-number-box :min="1" :max="exchMaxNum" v-model="exchNum"></uni-number-box>
  36. </view>
  37. <view class="goods-introduce uni-column uni-ais">
  38. <view class="goods-introduce-title">商品介绍:</view>
  39. <view class="goods-introduce-content" v-html="goodsRs.goodsDesc"></view>
  40. </view>
  41. <view class="goods-exchDesc" v-html="goodsRs.exchDesc"></view>
  42. </view>
  43. <button class="btnExchange" @click="btnExchange">兑 换</button>
  44. </view>
  45. <my-popup ref="mypopupExchg" :config="cardConfigData.popupExchgConfig" :dataList="cardConfigData.popupExchgList"></my-popup>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import tools from '/common/tools';
  51. import cardfunc from '../../../common/cardfunc';
  52. import {
  53. localCardConfig
  54. } from "./cardconfig/test.js";
  55. import {
  56. token,
  57. apiOnlineScoreQuery,
  58. apiCanExchangeGoodsDetail,
  59. apiScoreExchangeGoods,
  60. checkResCode
  61. } from '/common/api';
  62. export default {
  63. data() {
  64. return {
  65. cardConfigData: cardfunc.cardConfigData,
  66. pageReady: false,
  67. pageName: "goodsDetail",
  68. firstEnterKey: 'firstEnter-exchange-style1',
  69. queryObj: {},
  70. queryString: "",
  71. token: "",
  72. exchangeTitle: "商品详情",
  73. ecId: 0, // 卡片id
  74. goodsId: 0, // 商品id
  75. exchNum: 0, // 兑换数量
  76. exchMaxNum: 0, // 个人积分所能兑换的最大数量
  77. scoreRs: {
  78. score: 260, // 可用积分
  79. extTime: 0, // 积分到期时间戳
  80. },
  81. /* goodsRs: {
  82. goodsName: "", // 商品名称
  83. goodsPic: "", // 商品图片
  84. goodsLeftNum: 0, // 商品剩余数量
  85. corrScore: 0, // 兑换所需积分
  86. goodsUnit: "", // 商品单位
  87. goodsDesc: "", // 商品介绍
  88. exchDesc: "", // 兑换说明
  89. exchLimit: 0, // 个人兑换数量上限,0无限制
  90. } */
  91. goodsRs: {
  92. goodsName: "正宗农家土鸡蛋1枚", // 商品名称
  93. goodsPic: "/static/common/jidanquan.png", // 商品图片
  94. goodsLeftNum: 9, // 商品剩余数量
  95. corrScore: 20, // 兑换所需积分
  96. goodsUnit: "个", // 商品单位
  97. goodsDesc: "还记得小时候,奶奶亲手做的荷包蛋吗?那金黄的蛋黄,香浓的味道,至今让人回味无穷。我们的土鸡蛋,延续了传统的养殖方式,每一枚鸡蛋都承载着浓浓的乡愁。让您重温儿时的美好记忆。", // 商品介绍
  98. exchDesc: "兑换说明:<br>只限本次赛事积分在指定商超兑换。<br>有效期说明:<br>赛事结束后30天内可以兑换,过期失效!", // 兑换说明
  99. exchLimit: 3, // 个人兑换数量上限,0无限制
  100. }
  101. }
  102. },
  103. computed: {
  104. },
  105. onLoad(query) { // 类型非必填,可自动推导
  106. // console.log(query);
  107. this.queryObj = query;
  108. this.queryString = tools.objectToQueryString(this.queryObj);
  109. // console.log(queryString);
  110. this.token = query["token"] ?? token;
  111. this.ecId = query["id"] ?? 0;
  112. this.goodsId = query["goodsId"] ?? 0;
  113. this.firstEnterKey += "-" + this.ecId;
  114. console.log("firstEnterKey:", this.firstEnterKey);
  115. cardfunc.init(this, this.token, this.ecId);
  116. cardfunc.getCardConfig(this.cardConfigQueryCallback, localCardConfig);
  117. this.onlineScoreQuery();
  118. },
  119. // 页面初次渲染完成,此时组件已挂载完成,DOM 树($el)已可用
  120. onReady() {},
  121. onShow() {},
  122. onUnload() {},
  123. methods: {
  124. // 计算个人积分所能兑换的最大数量
  125. computeExchMaxNum() {
  126. if(!(this.scoreRs.score > 0 && this.goodsRs.corrScore > 0)) {
  127. return;
  128. }
  129. let maxNum = Math.floor(this.scoreRs.score / this.goodsRs.corrScore);
  130. if (this.goodsRs.exchLimit > 0 && maxNum > this.goodsRs.exchLimit) {
  131. maxNum = this.goodsRs.exchLimit;
  132. }
  133. if (maxNum > 0 && this.exchNum == 0) {
  134. this.exchNum = 1;
  135. }
  136. this.exchMaxNum = parseInt(maxNum);
  137. },
  138. fmtTime(timestamp, type = 3) {
  139. return tools.timestampToTime(timestamp * 1000, type);
  140. },
  141. cardConfigQueryCallback(cardconfig) {
  142. this.loadConfig(cardconfig);
  143. // setTimeout(this.dealFirstEnter, 500);
  144. },
  145. loadConfig(cardconfig) {
  146. cardconfig = cardfunc.parseCardConfig(cardconfig);
  147. // console.log("[loadCardConfig] cardconfig:", cardconfig);
  148. // 加载卡片通用配置
  149. if (cardconfig.common != undefined) {
  150. cardfunc.loadCardCommonConfig(cardconfig.common);
  151. }
  152. // -------- 加载当前页面的配置 --------
  153. const config = cardfunc.parseCardConfig(cardconfig[this.pageName]);
  154. // console.log("[loadConfig] config_page:", config);
  155. if (config == undefined || config == null) {
  156. this.pageReady = true;
  157. return;
  158. }
  159. // 加载CSS样式
  160. const css = config.css;
  161. if (css != undefined && css.length > 0) {
  162. tools.loadCssCode(css);
  163. }
  164. this.pageReady = true;
  165. },
  166. // 卡片内可用积分查询
  167. onlineScoreQuery() {
  168. uni.request({
  169. url: apiOnlineScoreQuery,
  170. header: {
  171. "Content-Type": "application/x-www-form-urlencoded",
  172. "token": this.token,
  173. },
  174. method: "POST",
  175. data: {
  176. ecId: this.ecId
  177. },
  178. success: (res) => {
  179. // console.log("onlineScoreQuery", res);
  180. if (checkResCode(res)) {
  181. this.scoreRs = res.data.data;
  182. this.canExchangeGoodsDetail();
  183. }
  184. },
  185. fail: (err) => {
  186. console.log("onlineScoreQuery err", err);
  187. },
  188. });
  189. },
  190. // 积分可兑换商品详情
  191. canExchangeGoodsDetail() {
  192. uni.request({
  193. url: apiCanExchangeGoodsDetail,
  194. header: {
  195. "Content-Type": "application/x-www-form-urlencoded",
  196. "token": this.token,
  197. },
  198. method: "POST",
  199. data: {
  200. ecId: this.ecId,
  201. goodsId: this.goodsId
  202. },
  203. success: (res) => {
  204. console.log("canExchangeGoodsDetail", res);
  205. this.goodsRs = res.data.data;
  206. this.computeExchMaxNum();
  207. },
  208. fail: (err) => {
  209. console.log("canExchangeGoodsDetail err", err);
  210. },
  211. });
  212. },
  213. // 积分兑换商品
  214. scoreExchangeGoods() {
  215. uni.request({
  216. url: apiScoreExchangeGoods,
  217. header: {
  218. "Content-Type": "application/x-www-form-urlencoded",
  219. "token": this.token,
  220. },
  221. method: "POST",
  222. data: {
  223. ecId: this.ecId,
  224. goodsId: this.goodsId,
  225. exchNum: this.exchNum
  226. },
  227. success: (res) => {
  228. // console.log("scoreExchangeGoods", res);
  229. if (checkResCode(res, "兑换失败: ")) {
  230. uni.showToast({
  231. title: '商品兑换成功!',
  232. icon: 'none',
  233. duration: 3000
  234. });
  235. this.onlineScoreQuery();
  236. /* setTimeout(() => {
  237. // const url = "/pages/exchange/style1/goodsList?" + this.queryString;
  238. // tools.appAction(url, "uni.navigateTo");
  239. tools.appAction("reload");
  240. }, 2000); */
  241. }
  242. },
  243. fail: (err) => {
  244. console.log("scoreExchangeGoods err", err);
  245. }
  246. });
  247. },
  248. btnExchange() {
  249. if (!(this.exchNum > 0)) {
  250. uni.showToast({
  251. title: '请输入兑换数量',
  252. icon: 'none',
  253. duration: 2000
  254. });
  255. return;
  256. }
  257. let that = this;
  258. uni.showModal({
  259. title: '兑换',
  260. content: `兑换数量:${this.exchNum} 消耗积分:${this.exchNum * this.goodsRs.corrScore}\r\n\r\n您确定要兑换吗?`,
  261. confirmText: '确定', //确定文本的文字
  262. cancelText: '取消', //确定文本的文字
  263. showCancel: true, //没有取消按钮的弹框
  264. success: function(res) {
  265. if (res.confirm) {
  266. that.scoreExchangeGoods();
  267. } else if (res.cancel) {
  268. }
  269. }
  270. })
  271. },
  272. btnBack() {
  273. const url = "/pages/exchange/style1/goodsList?" + this.queryString;
  274. tools.appAction(url, "uni.navigateTo");
  275. },
  276. btnInfo() {
  277. this.$refs.mypopupExchg.popupOpen();
  278. },
  279. }
  280. }
  281. </script>
  282. <style scoped>
  283. .content {
  284. width: 100vw;
  285. height: 100vh;
  286. background: linear-gradient(119.37deg, #FFEF9E 0%, #FFEEDB 31.6%, #FFF3C2 100%);
  287. }
  288. .exchg-top {
  289. width: 100%;
  290. /* height: 170px; */
  291. padding-top: 36px;
  292. justify-content: space-between;
  293. }
  294. .exchgbar-color {
  295. /* color: #000000; */
  296. }
  297. .main {
  298. width: 100%;
  299. flex-grow: 1;
  300. margin-top: 10px;
  301. padding-bottom: 20px;
  302. border-radius: 19px 19px 0px 0px;
  303. border: 1px solid #FFFFFF;
  304. background: #F6F6F6;
  305. }
  306. .top-content {
  307. position: relative;
  308. width: 90%;
  309. height: 30px;
  310. margin-top: 10px;
  311. }
  312. .scoreBox {
  313. width: 100%;
  314. height: 80%;
  315. margin-top: 10px;
  316. /* background-color: #A65600; */
  317. }
  318. .scoreBox-score {
  319. font-size: 12px;
  320. font-weight: 500;
  321. color: #A65600;
  322. }
  323. .scoreBox-score-ico {
  324. width: 19px;
  325. height: 15px;
  326. }
  327. .scoreBox-title {
  328. margin-right: 10px;
  329. font-size: 12px;
  330. font-weight: 550;
  331. color: #000000;
  332. }
  333. .scoreBox-score-value {
  334. margin: 0 6px;
  335. font-size: 18px;
  336. font-weight: 700;
  337. }
  338. .scoreBox-score-unite {
  339. margin-top: 12px;
  340. }
  341. .scoreBox-expire {
  342. font-size: 12px;
  343. font-weight: 500;
  344. color: #A6A6A6;
  345. }
  346. .goodsBox {
  347. width: 90%;
  348. margin-top: 20px;
  349. /* background-color: #FFEF9E; */
  350. }
  351. .goods-title {
  352. font-size: 16px;
  353. font-weight: 500;
  354. }
  355. .goods-pic {
  356. width: 90%;
  357. height: 160px;
  358. margin: 20px 0;
  359. }
  360. .goods-priceBox {
  361. width: 200px;
  362. height: 25px;
  363. padding: 2px 12px;
  364. border-radius: 3px;
  365. background: #FFC300;
  366. }
  367. .goods-scoreIco {
  368. width: 22px;
  369. height: 14px;
  370. margin-right: 3px;
  371. }
  372. .goods-priceBox-text {
  373. font-size: 14px;
  374. white-space: nowrap;
  375. }
  376. .goods-exchNumBox {
  377. margin: 20px;
  378. }
  379. ::v-deep .uni-numbox-btns {
  380. width: 10px;
  381. border: 1px solid #A6A6A6;
  382. }
  383. .goods-introduce {
  384. width: 90%;
  385. font-size: 14px;
  386. font-weight: 400;
  387. line-height: 20px;
  388. }
  389. .goods-introduce-title {
  390. width: 100%;
  391. margin-bottom: 10px;
  392. text-align: left;
  393. font-weight: 550;
  394. }
  395. .goods-exchDesc {
  396. width: 90%;
  397. margin-top: 20px;
  398. padding: 10px;
  399. border-radius: 5px;
  400. background: #FFF8E3;
  401. font-size: 12px;
  402. font-weight: 400;
  403. line-height: 20px;
  404. }
  405. .btnExchange {
  406. width: 289px;
  407. height: 53px;
  408. margin-top: 30px;
  409. margin-bottom: 20px;
  410. border-radius: 27px;
  411. background: linear-gradient(117.53deg, #FFCD29 0%, #FFE694 42.36%, #FFC508 100%);
  412. font-size: 18px;
  413. font-weight: 550;
  414. line-height: 53px;
  415. color: #A65600;
  416. }
  417. </style>