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

458 lines
11 KiB

  1. <template>
  2. <view>
  3. <view class="bargain_contanier">
  4. <view class="bargain_head">
  5. <image mode="widthFix" src="https://cdn.ibrand.cc/heads%20%281%29.png"></image>
  6. </view>
  7. <view class="rule" @tap="changeRule">
  8. 活动规则
  9. </view>
  10. <view class="body_box">
  11. <view class="bargain_body" v-for="(items,idx) in list" :key="idx">
  12. <view v-for="(item,index) in items" :key="index">
  13. <view class="bargain_goods">
  14. <view class="goods_left">
  15. <image mode="widthFix" :src="item.goods.img"></image>
  16. </view>
  17. <view class="goods_right">
  18. <view class="goods_name">{{item.goods.name}}</view>
  19. <view class="number">剩余{{item.store_nums}}砍价名额</view>
  20. <view class="past_price">原价 <span>{{item.goods.max_price}}</span></view>
  21. <view class="right_foot">
  22. <view class="new_price">
  23. 砍后价{{item.price}}
  24. </view>
  25. <!-- #ifdef MP-WEIXIN -->
  26. <view class="btn" @tap.native.stop="clickBargain" :data-id="item.id">
  27. 发起砍价
  28. </view>
  29. <button class="bind-btn" open-type="getUserInfo" @getuserinfo="bindUserInfo" style="opacity: 0;" v-if="token && !user_info_fill">
  30. </button>
  31. <!-- #endif -->
  32. <!-- #ifdef APP-PLUS ||H5 -->
  33. <view class="btn" @tap="clickBargain" :data-id="item.id">
  34. 发起砍价
  35. </view>
  36. <!-- #endif -->
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="box_body" v-if="show" @tap.stop="changeRule" @touchmove.stop="true">
  44. <scroll-view scroll-y class="rule_box">
  45. <text>{{rule}}</text>
  46. </scroll-view>
  47. <view class="iconfont icon-close" @tap.stop="changeRule"></view>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import uParse from '@/components/gaoyia-parse/parse.vue';
  54. import {
  55. pageLogin,
  56. getUrl,
  57. config,
  58. is
  59. } from '@/common/js/utils.js';
  60. export default {
  61. components: {
  62. uParse
  63. },
  64. data() {
  65. return {
  66. show: false,
  67. rule: '京东方公安三季度非附近的双方各见风使舵公开',
  68. list: [],
  69. prices: [],
  70. page: 1,
  71. more: true,
  72. user_info_fill:0,//用户是否完善信息
  73. token:''
  74. }
  75. },
  76. onLoad(e){
  77. // #ifdef H5
  78. var token = this.$cookieStorage.get('user_token');
  79. if(!token){
  80. var env = {
  81. isIPad: /ipad/i.test(window.navigator.userAgent),
  82. isIphone: /iphone|ipad|ipod/i.test(window.navigator.userAgent),
  83. isWechat: /MicroMessenger/i.test(window.navigator.userAgent)
  84. }
  85. if(env.isWechat){
  86. if(e.openid){
  87. this.$cookieStorage.set('openid',e.openid)
  88. }
  89. var openid = this.$cookieStorage.get('openid') || e.openid;
  90. if(openid){
  91. this.postNewQuickLogin(openid);
  92. } else{
  93. let origin = window.location.origin;
  94. var url = origin+'/pages/bargain/index/index';
  95. window.location.href = this.$config.GLOBAL.baseUrl+'oauth/wxOauth?redirect_url='+encodeURIComponent(url);
  96. }
  97. } else{
  98. let url = getUrl();
  99. wx.navigateTo({
  100. url:'/pages/user/loginType/loginType?url='+url
  101. })
  102. }
  103. }
  104. // #endif
  105. var windowHeight = wx.getSystemInfoSync().windowHeight //获取设备的高度
  106. var token = this.$cookieStorage.get('user_token');
  107. this.token = token;
  108. this.Height = windowHeight;
  109. this.getReduceList(1);
  110. this.getHelpText();
  111. if(token){
  112. this.getUserInfo()
  113. }
  114. },
  115. //下拉刷新
  116. onReachBottom(){
  117. if(this.more){
  118. let page = this.page + 1;
  119. this.getReduceList(page);
  120. } else {
  121. wx.showToast({
  122. image: '../../../static/error.png',
  123. title: '再拉也没有啦'
  124. });
  125. }
  126. },
  127. methods: {
  128. //h5微信登陆
  129. postNewQuickLogin(open_id){
  130. wx.showLoading({
  131. title: '正在登录',
  132. mask: true
  133. });
  134. this.$http.post({
  135. api:'api/oauth/newQuickLogin',
  136. data:{
  137. open_id:open_id
  138. }
  139. }).then(res=>{
  140. res = res.data;
  141. if(res.status){
  142. if(res.data.access_token){
  143. var access_token = res.data.token_type + ' ' + res.data.access_token;
  144. var expires_in = res.data.expires_in || 315360000;
  145. this.$cookieStorage.set("user_token", access_token, expires_in);
  146. //如果用户没有绑定手机号
  147. if(res.data.has_bind_mobile == 0){
  148. wx.reLaunch({
  149. url:'/pages/user/bindingphone/bindingphone'
  150. })
  151. }
  152. } else{
  153. wx.showModal({
  154. content: res.message || '请求失败,请重试',
  155. showCancel: false
  156. });
  157. }
  158. } else{
  159. wx.showModal({
  160. content: res.message || '请求失败,请重试',
  161. showCancel: false
  162. });
  163. }
  164. wx.hideLoading()
  165. }).catch(rej=>{
  166. wx.showModal({
  167. content: rej.message || '请求失败,请重试',
  168. showCancel: false
  169. });
  170. wx.hideLoading()
  171. })
  172. },
  173. //绑定用户信息
  174. bindUserInfo(e) {
  175. console.log(e)
  176. if (e.detail.encryptedData) {
  177. this.updateUserInfo(e.detail);
  178. }
  179. },
  180. updateUserInfo(data) {
  181. wx.showLoading({
  182. title: '更新中',
  183. mask: true
  184. });
  185. this.$http.get({
  186. api: 'api/user/bindUserMiniInfo',
  187. data: data,
  188. header: {
  189. Authorization: this.$cookieStorage.get('user_token')
  190. }
  191. }).then(res => {
  192. res = res.data;
  193. if (res.status) {
  194. wx.showModal({
  195. content:"用户信息更新完成,请砍价",
  196. showCancel:false
  197. })
  198. } else {
  199. wx.showModal({
  200. content: res.message || '请求失败',
  201. showCancel: false
  202. });
  203. }
  204. wx.hideLoading();
  205. });
  206. },
  207. //获取用户信息
  208. getUserInfo() {
  209. this.$http.get({
  210. api: 'api/me',
  211. header: {
  212. Authorization: this.$cookieStorage.get('user_token')
  213. }
  214. }).then(res => {
  215. res = res.data;
  216. if (res.status) {
  217. this.user_info_fill = res.data.user_info_fill
  218. }
  219. });
  220. },
  221. // 点击发起砍价按钮
  222. clickBargain(e) {
  223. let token = this.$cookieStorage.get('user_token');
  224. if (token) {
  225. // 发起砍价请求
  226. let id = e.currentTarget.dataset.id;
  227. this.id = id;
  228. this.postReduce(id);
  229. } else {
  230. // #ifdef MP-WEIXIN || APP-PLUS
  231. var url = getUrl();
  232. // #endif
  233. // #ifdef H5
  234. var url = getUrl();
  235. // #endif
  236. wx.showModal({
  237. content: '请先登录',
  238. success: res => {
  239. if (res.confirm) {
  240. // #ifdef APP-PLUS || MP-WEIXIN
  241. wx.navigateTo({
  242. url: '/pages/user/register/register?url=' + url
  243. });
  244. // #endif
  245. // #ifdef H5
  246. wx.navigateTo({
  247. url: '/pages/user/register/register?url=' + encodeURIComponent(url)
  248. });
  249. // #endif
  250. }
  251. }
  252. });
  253. }
  254. },
  255. // 发起砍价的请求
  256. postReduce(reduce_id) {
  257. wx.showLoading({
  258. title: "请求中",
  259. mask: true
  260. });
  261. let token = this.$cookieStorage.get('user_token');
  262. this.$http.post({
  263. api: 'api/reduce',
  264. header: {
  265. Authorization: token
  266. },
  267. data: {
  268. reduce_id: reduce_id
  269. }
  270. }).then(res => {
  271. res = res.data;
  272. if (res.status) {
  273. this.reduce_items_id = res.data.reduce_items_id
  274. // 判断是否可以跳砍价页面,如果不能就需要跳到订单详情页去
  275. this.getReduceShowItem();
  276. } else {
  277. wx.showModal({
  278. content: res.message || '请求失败',
  279. showCancel: false
  280. })
  281. }
  282. wx.hideLoading()
  283. }).catch(rej => {
  284. wx.showModal({
  285. content: rej.message || '请求失败',
  286. showCancel: false
  287. })
  288. wx.hideLoading()
  289. })
  290. },
  291. // 获取砍价的规则
  292. getHelpText() {
  293. this.$http.get({
  294. api: 'api/reduce/help/text'
  295. }).then(res => {
  296. res = res.data;
  297. if (res.status) {
  298. this.setData({
  299. rule: res.data.reduce_help_text
  300. })
  301. } else {
  302. wx.showModal({
  303. content: res.message || '请求失败',
  304. showCancel: false
  305. })
  306. }
  307. }).catch(rej => {
  308. wx.showModal({
  309. content: rej.message || '请求失败',
  310. showCancel: false
  311. })
  312. })
  313. },
  314. // 请求是否是可以跳到砍价详情页
  315. getReduceShowItem() {
  316. var token = this.$cookieStorage.get('user_token');
  317. this.$http.get({
  318. api: `api/reduce/showItem?reduce_items_id=${this.reduce_items_id}`,
  319. header: {
  320. Authorization: token
  321. }
  322. }).then(res => {
  323. res = res.data;
  324. if (res.status) {
  325. if (res.data.order != null) {
  326. if (res.data.order.status == 1) {
  327. {
  328. wx.navigateTo({
  329. url: `/pages/order/detail/detail?no=${res.data.order.order_no}`
  330. })
  331. }
  332. } else {
  333. wx.navigateTo({
  334. url: `/pages/bargain/detail/detail?reduce_items_id=${this.reduce_items_id}&id=${this.id}`
  335. })
  336. }
  337. } else {
  338. wx.navigateTo({
  339. url: `/pages/bargain/detail/detail?reduce_items_id=${this.reduce_items_id}&id=${this.id}`
  340. })
  341. }
  342. } else {
  343. wx.showModal({
  344. content: res.message || '请求失败',
  345. showCancel: false
  346. })
  347. }
  348. })
  349. },
  350. // 弹起活动规则
  351. changeRule() {
  352. this.setData({
  353. show:!this.show
  354. })
  355. },
  356. // 获取页面列表数据
  357. getReduceList(page) {
  358. wx.showLoading({
  359. title: "加载中",
  360. mask: true
  361. });
  362. this.$http.get({
  363. api: 'api/reduce/list',
  364. data: {
  365. page:page
  366. }
  367. }).then(res => {
  368. res = res.data;
  369. if (res.status) {
  370. let pages = res.meta.pagination;
  371. let current_page = pages.current_page;
  372. let total_pages = pages.total_pages;
  373. this.setData({
  374. [`list.${page-1}`]: res.data,
  375. more: current_page < total_pages,
  376. page: current_page
  377. })
  378. } else {
  379. wx.showModal({
  380. content: res.message || '请求失败',
  381. showCancel: false
  382. })
  383. }
  384. this.setData({
  385. show: false
  386. })
  387. wx.hideLoading()
  388. }).catch(rej => {
  389. wx.hideLoading()
  390. wx.showModal({
  391. content: rej.message || '请求失败',
  392. showCancel: false
  393. })
  394. })
  395. },
  396. setData: function(obj) {
  397. let that = this;
  398. let keys = [];
  399. let val, data;
  400. Object.keys(obj).forEach(function(key) {
  401. keys = key.split('.');
  402. val = obj[key];
  403. data = that.$data;
  404. keys.forEach(function(key2, index) {
  405. if (index + 1 == keys.length) {
  406. that.$set(data, key2, val);
  407. } else {
  408. if (!data[key2]) {
  409. that.$set(data, key2, {});
  410. }
  411. }
  412. data = data[key2];
  413. });
  414. });
  415. }
  416. }
  417. }
  418. </script>
  419. <style rel="stylesheet/less" lang="less">
  420. @import "index";
  421. </style>