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

375 lines
10 KiB

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