金诚优选前端代码
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.

341 lines
8.8 KiB

  1. <template>
  2. <view id="on-detail" v-if="init">
  3. <!--<view class="top">
  4. <view>{{detail.discount.title}}</view>
  5. <view>{{detail.discount.starts_at}} {{detail.discount.ends_at}}</view>
  6. </view>
  7. <view class="code">
  8. {{detail.code}}
  9. </view>
  10. <view class="tips">
  11. <view>使用条件 : {{detail.discount.label}}</view>
  12. <view>使用规则 : {{detail.discount.intro}}</view>
  13. </view>-->
  14. <view class="coupon">
  15. <view class="coupon-left" :class="is_coupon != 1 ? 'discount' : ''" :style="'background: ' + config.mainColor">
  16. <view class="text-wrap">
  17. <view class="text-box">
  18. <view class="text">
  19. <text class="money" v-if="detail.action_type.type == 'cash'"></text>
  20. <sapn>{{ detail.action_type.value }}</sapn>
  21. <text class="money" v-if="detail.action_type.type == 'discount'"></text>
  22. </view>
  23. <text class="label text">{{ detail.label }}</text>
  24. </view>
  25. </view>
  26. <view class="dot-wrap">
  27. <view class="dot-item">
  28. </view>
  29. <view class="dot-item">
  30. </view>
  31. <view class="dot-item">
  32. </view>
  33. <view class="dot-item">
  34. </view>
  35. <view class="dot-item">
  36. </view>
  37. <view class="dot-item">
  38. </view>
  39. </view>
  40. </view>
  41. <view class="coupon-right">
  42. <view class="top">
  43. <span class="type">
  44. <span v-if="detail.channel == 'ec'">商城</span>
  45. <span v-else>门店</span>
  46. </span>
  47. <text class="info">{{detail.title}}</text>
  48. </view>
  49. <view class="bottom">
  50. <view class="bottom-use">
  51. <view class="tiem-box">
  52. <text>{{detail.use_start_time}}{{detail.use_end_time}}</text>
  53. </view>
  54. <view v-if="is_coupon == 1">
  55. <view class="btn use" :style="'background: ' + config.mainColor" v-if="!detail.has_get" @tap.stop="getCoupon">
  56. 点击领取
  57. </view>
  58. <view class="btn already" :style="'color: ' + config.mainColor + '; border-color: ' + config.mainColor" v-else @tap.stop="jumpList">
  59. 去使用
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="detail-item user-info" v-if="detail.intro">
  67. <view class="title">
  68. 使用说明
  69. </view>
  70. <view class="info mx-1px-top">
  71. {{detail.intro}}
  72. </view>
  73. </view>
  74. <view class="home" @tap="jumpHome" :style="'background: ' + config.mainColor">
  75. <i class="iconfont icon--shouye"></i>
  76. <view>
  77. 首页
  78. </view>
  79. </view>
  80. <view class="button-box" v-if="is_coupon == 1">
  81. <view class="btn" :style="'background: ' + config.mainColor" v-if="!detail.has_get" @tap.stop="getCoupon">
  82. 点击领取
  83. </view>
  84. <view class="btn" :style="'background: ' + config.mainColor" v-else @tap.stop="jumpList">
  85. 去使用
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. import {pageLogin, getUrl,config} from '@/common/js/utils.js';
  92. export default {
  93. data() {
  94. return {
  95. detail: '',
  96. is_coupon: 1,
  97. // 用于判断是否为优惠券 1:优惠券 0:促销折扣
  98. init: false,
  99. agent_code: '',
  100. config: ''
  101. };
  102. },
  103. onLoad(e) {
  104. // 第三方平台配置颜色
  105. var gbConfig = this.$cookieStorage.get('globalConfig') || '';
  106. this.setData({
  107. config: gbConfig
  108. });
  109. var id = e.id;
  110. var coupon_id = e.coupon_id;
  111. var agent_code = e.agent_code || '';
  112. var is_coupon = e.is_coupon || '';
  113. const timeMap = {
  114. y: 31536000000,
  115. m: 2592000000,
  116. d: 86400000,
  117. h: 3600000,
  118. n: 60000,
  119. s: 1000
  120. }; // 默认有效期为7天
  121. var valid_time = "";
  122. if (e.scene) {
  123. var scene = decodeURIComponent(e.scene);
  124. var sceneArr = scene.split('_');
  125. if (sceneArr.length > 0) {
  126. id = sceneArr[0];
  127. agent_code = sceneArr[1];
  128. is_coupon = 1;
  129. }
  130. }
  131. if (!this.$cookieStorage.get('distribution_valid_time')) {
  132. valid_time = 10080;
  133. } else {
  134. valid_time = this.$cookieStorage.get('distribution_valid_time');
  135. }
  136. let timeStamp = new Date().getTime();
  137. timeStamp += timeMap.n * valid_time;
  138. if (agent_code) {
  139. // 推客优惠券的agent_code
  140. this.$cookieStorage.set('coupon_agent_code', agent_code, valid_time + 'n');
  141. }
  142. this.setData({
  143. agent_code: agent_code
  144. });
  145. this.queryCouponDetail(id);
  146. if (is_coupon) {
  147. if (is_coupon != 1) {
  148. wx.setNavigationBarTitle({
  149. title: '线上折扣券详情'
  150. });
  151. } else {
  152. wx.setNavigationBarTitle({
  153. title: '线上优惠券详情'
  154. });
  155. }
  156. this.setData({
  157. is_coupon: e.is_coupon
  158. });
  159. } else {
  160. wx.setNavigationBarTitle({
  161. title: '线上折扣券详情'
  162. });
  163. }
  164. },
  165. methods: {
  166. jumpList(e) {
  167. wx.navigateTo({
  168. url: '/pages/coupon/goods/goods?id=' + this.detail.coupon_id
  169. });
  170. },
  171. jumpHome() {
  172. wx.switchTab({
  173. url: '/pages/index/index/index'
  174. });
  175. },
  176. getCoupon() {
  177. var token = this.$cookieStorage.get('user_token');
  178. if (token) {
  179. this.convertCoupon(this.detail.code);
  180. } else {
  181. wx.showModal({
  182. content: '请先登录',
  183. showCancel: false,
  184. success: res => {
  185. if (res.confirm || !res.cancel && !res.confirm) {
  186. pageLogin(getUrl());
  187. }
  188. }
  189. });
  190. }
  191. },
  192. // 领取优惠券接口
  193. convertCoupon(code) {
  194. var token = this.$cookieStorage.get('user_token');
  195. wx.showLoading({
  196. title: "正在领取",
  197. mask: true
  198. });
  199. this.$http.post({
  200. api: 'api/coupon/convert',
  201. header: {
  202. Authorization: token
  203. },
  204. data: {
  205. coupon_code: code,
  206. agent_code: this.agent_code
  207. }
  208. }).then(res => {
  209. wx.hideLoading();
  210. if (res.statusCode == 200) {
  211. res = res.data;
  212. if (res.status) {
  213. this.setData({
  214. 'detail.has_get': true
  215. });
  216. wx.showToast({
  217. title: '领取成功'
  218. });
  219. } else {
  220. wx.showToast({
  221. title: res.message || '领取失败',
  222. image: '../../../static/error.png'
  223. });
  224. }
  225. } else {
  226. wx.showToast({
  227. title: '领取失败',
  228. image: '../../../static/error.png'
  229. });
  230. }
  231. }).catch(rej => {
  232. wx.showToast({
  233. title: '领取失败',
  234. image: '../../../static/error.png'
  235. });
  236. wx.hideLoading();
  237. });
  238. },
  239. // 查询优惠券详情
  240. queryCouponDetail(id) {
  241. wx.showLoading({
  242. title: "加载中",
  243. mask: true
  244. });
  245. var token = this.$cookieStorage.get('user_token');
  246. this.$http.get({
  247. api: 'api/discount/' + id + '/detail',
  248. header: {
  249. Authorization: token
  250. }
  251. }).then(res => {
  252. if (res.statusCode == 200) {
  253. res = res.data;
  254. if (res.status) {
  255. this.setData({
  256. detail: res.data,
  257. init: true
  258. });
  259. } else {
  260. wx.showModal({
  261. content: res.message || '请求失败',
  262. showCancel: false
  263. });
  264. }
  265. } else {
  266. wx.showModal({
  267. content: "请求失败",
  268. showCancel: false
  269. });
  270. }
  271. wx.hideLoading();
  272. }).catch(rej => {
  273. wx.hideLoading();
  274. wx.showModal({
  275. content: '请求失败',
  276. showCancel: false
  277. });
  278. });
  279. },
  280. setData: function (obj) {
  281. let that = this;
  282. let keys = [];
  283. let val, data;
  284. Object.keys(obj).forEach(function (key) {
  285. keys = key.split('.');
  286. val = obj[key];
  287. data = that.$data;
  288. keys.forEach(function (key2, index) {
  289. if (index + 1 == keys.length) {
  290. that.$set(data, key2, val);
  291. } else {
  292. if (!data[key2]) {
  293. that.$set(data, key2, {});
  294. }
  295. }
  296. data = data[key2];
  297. });
  298. });
  299. }
  300. },
  301. computed: {},
  302. watch: {}
  303. };
  304. </script>
  305. <style rel="stylesheet/less" lang="less">
  306. @import "onDetail";
  307. </style>