detail-bottom-button.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <view class="detail-bottom-button">
  3. <view class="dir-left-nowrap" v-if="active">
  4. <view class="but" @click="route_jump">
  5. <app-form-id>
  6. <view class="but dir-top-nowrap main-left cross-center border-left">
  7. <image class="icon" src="/static/image/icon/index.png"></image>
  8. <text class="text">首页</text>
  9. </view>
  10. </app-form-id>
  11. </view>
  12. <view class="but" @click="set_favorite(favorite)">
  13. <app-form-id>
  14. <view class="but dir-top-nowrap main-left cross-center">
  15. <image class="icon"
  16. :src="favorite ? '/static/image/icon/icon-favorite-active.png' : '/static/image/icon/icon-favorite.png'">
  17. </image>
  18. <text class="text">收藏</text>
  19. </view>
  20. </app-form-id>
  21. </view>
  22. <view class="buttons dir-left-nowrap" v-if="detail.goods_num == 0">
  23. <view class="dir-top-nowrap main-center cross-center"
  24. style="background-color: #CDCDCD;color: #fff;width: 100%;">
  25. <text>已售罄</text>
  26. </view>
  27. </view>
  28. <view v-else class="buttons dir-left-nowrap">
  29. <view class="advance-title dir-top-nowrap main-center cross-center"
  30. :class="theme === 'b' || theme === 'a' || theme === 'f' ? theme+ '-s-back ' + 'text ' + theme : theme+ '-s-back ' + theme+ '-m-text ' + theme">
  31. <text>预售截止</text>
  32. <text>{{getDate(end_prepayment_at)}}</text>
  33. </view>
  34. <view class="pay" :class="theme+ '-m-back ' + theme" @click="set_active">
  35. <app-form-id>
  36. <text>
  37. 支付定金
  38. </text>
  39. </app-form-id>
  40. </view>
  41. </view>
  42. </view>
  43. <view v-if="!active" class="dir-left-nowrap">
  44. <view class="title dir-top-nowrap main-center cross-center"
  45. :class="theme === 'b' || theme === 'a' || theme === 'f' ? theme+ '-s-back ' + 'text ' + theme : theme+ '-s-back ' + theme+ '-m-text ' + theme">
  46. <text>预售截止</text>
  47. <text>{{getDate(end_prepayment_at)}}</text>
  48. </view>
  49. <view class="pay" :class="[theme+ '-m-back ' + theme, buttonDisabled ? 'dis-button' : '']" @click="pay">
  50. <text>
  51. 支付定金
  52. </text>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. export default {
  59. name: "detail-bottom-button",
  60. data() {
  61. return {
  62. request_time: false,
  63. once_pay: false,
  64. }
  65. },
  66. props: {
  67. end_prepayment_at: String,
  68. active: Boolean,
  69. favorite: Boolean,
  70. goods_id: Number,
  71. detail: Object,
  72. num: Number,
  73. theme: String,
  74. buttonDisabled: Boolean,
  75. service_label: Object
  76. },
  77. methods: {
  78. set_active() {
  79. if (this.$user.isLogin() && this.$store.state.user.info) {
  80. let member_level = this.$store.state.user.info.identity.member_level;
  81. if (member_level < this.detail.member_level) {
  82. uni.showModal({
  83. title: "提示",
  84. content: "需达到" + this.detail.member_name + "会员才可购买",
  85. showCancel: true,
  86. buttonText: '升级',
  87. success: (res) => {
  88. if (res.confirm) {
  89. uni.navigateTo({
  90. // url:"/pages/member/index/index",
  91. url: '/pages/member/upgrade/upgrade?level=' + member_level +
  92. '&other=' + this.detail.member_level
  93. })
  94. } else if (res.cancel) {
  95. console.log('用户点击取消');
  96. }
  97. }
  98. })
  99. return;
  100. }
  101. }
  102. if (this.$user.isLogin() && !this.once_pay) {
  103. this.$emit('close_attr', false);
  104. } else if (!this.$user.isLogin()) {
  105. this.$user.getInfo().then(() => {}).catch(() => {});
  106. }
  107. },
  108. set_favorite(data) {
  109. if (data) {
  110. this.$request({
  111. url: this.$api.user.favorite_remove,
  112. data: {
  113. goods_id: this.goods_id,
  114. }
  115. }).then(res => {
  116. if (res.code === 0) {
  117. this.$emit('favorite', !this.favorite);
  118. } else {
  119. uni.showModal({
  120. title: '提示',
  121. content: res.msg
  122. })
  123. }
  124. })
  125. } else {
  126. this.$request({
  127. url: this.$api.user.favorite_add,
  128. data: {
  129. goods_id: this.goods_id,
  130. }
  131. }).then(res => {
  132. if (res.code === 0) {
  133. this.$emit('favorite', !this.favorite);
  134. } else {
  135. uni.showModal({
  136. title: '提示',
  137. content: res.msg
  138. })
  139. }
  140. })
  141. }
  142. },
  143. route_jump() {
  144. uni.navigateTo({
  145. url: `/pages/index/index`,
  146. });
  147. },
  148. submit(body) {
  149. this.once_pay = true;
  150. uni.showLoading({
  151. title: '生成订单中...',
  152. mask: true,
  153. });
  154. this.$emit('close_attr', true);
  155. this.get_submit(body).then(response => {
  156. this.get_token(response.data);
  157. });
  158. },
  159. pay() {
  160. console.log(this.detail, "========-----------")
  161. if (this.buttonDisabled) return;
  162. if (this.service_label == null) {
  163. uni.showModal({
  164. title: "温馨提示",
  165. content: "您购买碎屏险了吗 ?",
  166. showCancel: true,
  167. confirmText: '去购买',
  168. success: (res) => {
  169. if (res.confirm) {
  170. return
  171. } else if (res.cancel) {
  172. if (this.$user.isLogin() && this.$store.state.user.info) {
  173. let member_level = this.$store.state.user.info.identity.member_level;
  174. if (member_level < this.detail.member_level) {
  175. uni.showModal({
  176. title: "提示",
  177. content: "需达到" + this.detail.member_name + "会员才可购买",
  178. showCancel: true,
  179. buttonText: '升级',
  180. success: (res) => {
  181. if (res.confirm) {
  182. uni.navigateTo({
  183. // url:"/pages/member/index/index",
  184. url: '/pages/member/upgrade/upgrade?level=' +
  185. member_level +
  186. '&other=' + this.detail
  187. .member_level
  188. })
  189. } else if (res.cancel) {
  190. console.log('用户点击取消');
  191. }
  192. }
  193. })
  194. return;
  195. }
  196. }
  197. let body = {
  198. goods_id: this.detail.id,
  199. goods_attr_id: 0,
  200. goods_num: `${this.num}`,
  201. advance_goods_id: this.detail.advanceGoods.id,
  202. service_label: JSON.stringify(this.service_label)
  203. };
  204. let attr = ``;
  205. let attr_groups = this.detail.attr_groups;
  206. for (let i = 0; i < attr_groups.length; i++) {
  207. let attr_list = attr_groups[i];
  208. for (let j = 0; j < attr_list.attr_list.length; j++) {
  209. if (attr_list.attr_list[j].active) {
  210. attr += `:${attr_list.attr_list[j].attr_id}`
  211. }
  212. }
  213. }
  214. for (let i = 0; i < this.detail.attr.length; i++) {
  215. if (this.detail.attr[i].sign_id === attr.substring(1)) {
  216. if (this.num > this.detail.attr[i].stock) {
  217. uni.showToast({
  218. title: '库存不足',
  219. icon: 'none'
  220. });
  221. return;
  222. }
  223. body.goods_attr_id = this.detail.attr[i].id;
  224. }
  225. }
  226. this.$subscribe(this.detail.template_message).then(() => {
  227. this.submit(body);
  228. }).catch(() => {
  229. this.submit(body);
  230. });
  231. }
  232. }
  233. })
  234. }else{
  235. if (this.$user.isLogin() && this.$store.state.user.info) {
  236. let member_level = this.$store.state.user.info.identity.member_level;
  237. if (member_level < this.detail.member_level) {
  238. uni.showModal({
  239. title: "提示",
  240. content: "需达到" + this.detail.member_name + "会员才可购买",
  241. showCancel: true,
  242. buttonText: '升级',
  243. success: (res) => {
  244. if (res.confirm) {
  245. uni.navigateTo({
  246. // url:"/pages/member/index/index",
  247. url: '/pages/member/upgrade/upgrade?level=' +
  248. member_level +
  249. '&other=' + this.detail
  250. .member_level
  251. })
  252. } else if (res.cancel) {
  253. console.log('用户点击取消');
  254. }
  255. }
  256. })
  257. return;
  258. }
  259. }
  260. let body = {
  261. goods_id: this.detail.id,
  262. goods_attr_id: 0,
  263. goods_num: `${this.num}`,
  264. advance_goods_id: this.detail.advanceGoods.id,
  265. service_label: JSON.stringify(this.service_label)
  266. };
  267. let attr = ``;
  268. let attr_groups = this.detail.attr_groups;
  269. for (let i = 0; i < attr_groups.length; i++) {
  270. let attr_list = attr_groups[i];
  271. for (let j = 0; j < attr_list.attr_list.length; j++) {
  272. if (attr_list.attr_list[j].active) {
  273. attr += `:${attr_list.attr_list[j].attr_id}`
  274. }
  275. }
  276. }
  277. for (let i = 0; i < this.detail.attr.length; i++) {
  278. if (this.detail.attr[i].sign_id === attr.substring(1)) {
  279. if (this.num > this.detail.attr[i].stock) {
  280. uni.showToast({
  281. title: '库存不足',
  282. icon: 'none'
  283. });
  284. return;
  285. }
  286. body.goods_attr_id = this.detail.attr[i].id;
  287. }
  288. }
  289. this.$subscribe(this.detail.template_message).then(() => {
  290. this.submit(body);
  291. }).catch(() => {
  292. this.submit(body);
  293. });
  294. }
  295. },
  296. get_token(data) {
  297. this.$request({
  298. url: this.$api.advance.pay_data,
  299. method: 'post',
  300. data: {
  301. ...data
  302. },
  303. }).then(response => {
  304. if (response.code === 0) {
  305. if (response.data.hasOwnProperty('id')) {
  306. uni.hideLoading();
  307. this.$payment.pay(response.data.id).then(() => {
  308. this.once_pay = false;
  309. // 支付成功
  310. uni.navigateTo({
  311. url: `/plugins/advance/order/order`
  312. })
  313. }).catch(() => {
  314. // 支付失败
  315. this.once_pay = false;
  316. uni.navigateTo({
  317. url: `/plugins/advance/order/order`
  318. })
  319. });
  320. } else {
  321. setTimeout(() => {
  322. this.get_token(data);
  323. }, 1000);
  324. }
  325. } else {
  326. uni.hideLoading();
  327. uni.showModal({
  328. title: '提示',
  329. content: response.msg,
  330. })
  331. }
  332. });
  333. },
  334. async get_submit(body) {
  335. const response = await this.$request({
  336. url: this.$api.advance.order_submit,
  337. method: 'post',
  338. data: {
  339. ...body,
  340. }
  341. });
  342. if (response.code === 0) {
  343. return response;
  344. } else if (response.code === 1) {
  345. uni.showModal({
  346. title: '提示',
  347. content: response.msg,
  348. success(res) {
  349. if (res.cancel) {
  350. this.$emit('request', this.goods_id);
  351. } else if (res.confirm) {
  352. uni.navigateBack();
  353. }
  354. }
  355. });
  356. }
  357. },
  358. getDate(end_prepayment_at) {
  359. let newDate = new Date(end_prepayment_at.replace(/-/g, '/'));
  360. newDate.setDate(newDate.getDate());
  361. let month = newDate.getMonth() + 1;
  362. let day = newDate.getDate();
  363. let mm = "'" + month + "'";
  364. let dd = "'" + day + "'";
  365. if (mm.length == 3) {
  366. month = "0" + month;
  367. }
  368. if (dd.length == 3) {
  369. day = "0" + day;
  370. }
  371. let hour = newDate.getHours(); //得到小时
  372. let minu = newDate.getMinutes(); //得到分钟
  373. let sec = newDate.getSeconds(); //得到秒
  374. sec = `${sec}`;
  375. minu = `${minu}`;
  376. hour = `${hour}`;
  377. if (hour.length === 1) {
  378. hour = `0${hour}`
  379. }
  380. if (minu.length === 1) {
  381. minu = `0${minu}`
  382. }
  383. if (sec.length === 1) {
  384. sec = `0${sec}`
  385. }
  386. return newDate.getFullYear() + "." + month + "." + day + ' ' + hour + ':' + minu + ':' + sec;
  387. },
  388. },
  389. }
  390. </script>
  391. <style scoped lang="scss">
  392. .detail-bottom-button {
  393. height: #{110rpx};
  394. width: #{750rpx};
  395. border-top: #{1rpx} solid #e3e3e3;
  396. .dir-left-nowrap {
  397. view {
  398. height: #{110rpx};
  399. }
  400. .but {
  401. width: #{105rpx};
  402. .text {
  403. font-size: #{20rpx};
  404. color: #707070;
  405. margin-top: #{9rpx};
  406. }
  407. }
  408. .border-left {
  409. border-right: #{1rpx} solid #e3e3e3;
  410. }
  411. .buttons {
  412. width: #{272+272rpx};
  413. }
  414. .title {
  415. width: 50%;
  416. height: #{110rpx};
  417. font-size: #{24rpx};
  418. margin: 0;
  419. }
  420. .pay {
  421. width: 50%;
  422. height: #{110rpx};
  423. line-height: #{110rpx};
  424. text-align: center;
  425. color: #ffffff;
  426. font-size: #{28rpx};
  427. }
  428. }
  429. .icon {
  430. width: #{40rpx};
  431. height: #{40rpx};
  432. margin-top: #{21rpx};
  433. }
  434. .text {
  435. color: #ffffff;
  436. }
  437. }
  438. .advance-title {
  439. width: 50%;
  440. height: #{110rpx};
  441. font-size: #{24rpx};
  442. margin: 0;
  443. }
  444. .dis-button {
  445. background-color: #dddddd;
  446. }
  447. </style>