detail-bottom-button.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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 border-left">
  15. <image class="icon" :src="favorite ? '/static/image/icon/icon-favorite-active.png' : '/static/image/icon/icon-favorite.png'"></image>
  16. <text class="text">收藏</text>
  17. </view>
  18. </app-form-id>
  19. </view>
  20. <view class="but" @click="kefu">
  21. <app-form-id>
  22. <view class="but dir-top-nowrap main-left cross-center">
  23. <image class="icon" src="/static/image/icon/icon-kefu.png"></image>
  24. <text class="text">客服</text>
  25. </view>
  26. </app-form-id>
  27. </view>
  28. <view class="buttons dir-left-nowrap" v-if="detail.goods_num == 0">
  29. <view class="dir-top-nowrap main-center cross-center" style="background-color: #CDCDCD;color: #fff;width: 100%;">
  30. <text>已售罄</text>
  31. </view>
  32. </view>
  33. <view v-else class="buttons dir-left-nowrap">
  34. <view class="advance-title dir-top-nowrap main-center cross-center cart-btn" style="height: 80%;color: #ffffff;"
  35. :class="theme === 'b' || theme === 'a' || theme === 'f' ? theme+ '-s-back ' + 'text ' + theme : theme+ '-s-back ' + theme+ '-m-text ' + theme">
  36. <text>预售截止</text>
  37. <text style=" word-break: break-all;
  38. text-overflow: ellipsis;
  39. display: -webkit-box;
  40. -webkit-box-orient: vertical;
  41. -webkit-line-clamp: 1;
  42. overflow: hidden;
  43. font-size: 20rpx;
  44. white-space: normal !important;">{{getDate(end_prepayment_at)}}</text>
  45. </view>
  46. <view class="pay buy-btn" style="height: 80%;color: #ffffff;" :class="theme+ '-m-back ' + theme" @click="set_active">
  47. <app-form-id>
  48. <text>
  49. 支付定金
  50. </text>
  51. </app-form-id>
  52. </view>
  53. </view>
  54. </view>
  55. <view v-if="!active" class="dir-left-nowrap">
  56. <view class="title dir-top-nowrap main-center cross-center cart-btn" style="height: 85rpx;color: #ffffff;transform: none;" :class="theme === 'b' || theme === 'a' || theme === 'f' ? theme+ '-s-back ' + 'text ' + theme : theme+ '-s-back ' + theme+ '-m-text ' + theme">
  57. <text>预售截止</text>
  58. <text>{{getDate(end_prepayment_at)}}</text>
  59. </view>
  60. <view class="pay buy-btn" style="height: 85rpx;color: #ffffff;transform: none;" :class="[theme+ '-m-back ' + theme, buttonDisabled ? 'dis-button' : '']"
  61. @click="pay">
  62. <text>
  63. 支付定金
  64. </text>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. export default {
  71. name: "detail-bottom-button",
  72. data() {
  73. return {
  74. request_time: false,
  75. once_pay: false,
  76. }
  77. },
  78. props: {
  79. end_prepayment_at: String,
  80. active: Boolean,
  81. favorite: Boolean,
  82. goods_id: Number,
  83. detail: Object,
  84. num: Number,
  85. theme: String,
  86. buttonDisabled: Boolean
  87. },
  88. methods: {
  89. set_active() {
  90. if (this.$user.isLogin() && !this.once_pay) {
  91. this.$emit('close_attr', false);
  92. } else if (!this.$user.isLogin()) {
  93. this.$user.getInfo().then(() => {}).catch(() => {});
  94. }
  95. },
  96. set_favorite(data) {
  97. if (data) {
  98. this.$request({
  99. url: this.$api.user.favorite_remove,
  100. data: {
  101. goods_id: this.goods_id,
  102. }
  103. }).then(res => {
  104. if (res.code === 0) {
  105. this.$emit('favorite', !this.favorite);
  106. } else {
  107. uni.showModal({
  108. title: '提示',
  109. content: res.msg
  110. })
  111. }
  112. })
  113. } else {
  114. this.$request({
  115. url: this.$api.user.favorite_add,
  116. data: {
  117. goods_id: this.goods_id,
  118. }
  119. }).then(res => {
  120. if (res.code === 0) {
  121. this.$emit('favorite', !this.favorite);
  122. } else {
  123. uni.showModal({
  124. title: '提示',
  125. content: res.msg
  126. })
  127. }
  128. })
  129. }
  130. },
  131. kefu() {
  132. uni.navigateTo({
  133. url: "/pages/web/web?url=" + this.mall.setting.web_service_url
  134. })
  135. },
  136. route_jump() {
  137. uni.navigateTo({
  138. url: `/pages/index/index`,
  139. });
  140. },
  141. submit(body) {
  142. this.once_pay = true;
  143. uni.showLoading({
  144. title: '生成订单中...',
  145. mask: true,
  146. });
  147. this.$emit('close_attr', true);
  148. this.get_submit(body).then(response => {
  149. this.get_token(response.data);
  150. });
  151. },
  152. pay() {
  153. if (this.buttonDisabled) return;
  154. let body = {
  155. goods_id: this.detail.id,
  156. goods_attr_id: 0,
  157. goods_num: `${this.num}`,
  158. advance_goods_id: this.detail.advanceGoods.id,
  159. };
  160. let attr = ``;
  161. let attr_groups = this.detail.attr_groups;
  162. for (let i = 0; i < attr_groups.length; i++) {
  163. let attr_list = attr_groups[i];
  164. for (let j = 0; j < attr_list.attr_list.length; j++) {
  165. if (attr_list.attr_list[j].active) {
  166. attr += `:${attr_list.attr_list[j].attr_id}`
  167. }
  168. }
  169. }
  170. for (let i = 0; i < this.detail.attr.length; i++) {
  171. if (this.detail.attr[i].sign_id === attr.substring(1)) {
  172. if (this.num > this.detail.attr[i].stock) {
  173. uni.showToast({
  174. title: '库存不足',
  175. icon: 'none'
  176. });
  177. return;
  178. }
  179. body.goods_attr_id = this.detail.attr[i].id;
  180. }
  181. }
  182. this.$subscribe(this.detail.template_message).then(() => {
  183. this.submit(body);
  184. }).catch(() => {
  185. this.submit(body);
  186. });
  187. },
  188. get_token(data) {
  189. this.$request({
  190. url: this.$api.advance.pay_data,
  191. method: 'post',
  192. data: {
  193. ...data
  194. },
  195. }).then(response => {
  196. if (response.code === 0) {
  197. if (response.data.hasOwnProperty('id')) {
  198. uni.hideLoading();
  199. this.$payment.pay(response.data.id).then(() => {
  200. this.once_pay = false;
  201. // 支付成功
  202. uni.navigateTo({
  203. url: `/plugins/advance/order/order`
  204. })
  205. }).catch(() => {
  206. // 支付失败
  207. this.once_pay = false;
  208. uni.navigateTo({
  209. url: `/plugins/advance/order/order`
  210. })
  211. });
  212. } else {
  213. setTimeout(() => {
  214. this.get_token(data);
  215. }, 1000);
  216. }
  217. } else {
  218. uni.hideLoading();
  219. uni.showModal({
  220. title: '提示',
  221. content: response.msg,
  222. })
  223. }
  224. });
  225. },
  226. async get_submit(body) {
  227. const response = await this.$request({
  228. url: this.$api.advance.order_submit,
  229. method: 'post',
  230. data: {
  231. ...body,
  232. }
  233. });
  234. if (response.code === 0) {
  235. return response;
  236. } else if (response.code === 1) {
  237. uni.showModal({
  238. title: '提示',
  239. content: response.msg,
  240. success(res) {
  241. if (res.cancel) {
  242. this.$emit('request', this.goods_id);
  243. } else if (res.confirm) {
  244. uni.navigateBack();
  245. }
  246. }
  247. });
  248. }
  249. },
  250. getDate(end_prepayment_at) {
  251. let newDate = new Date(end_prepayment_at.replace(/-/g, '/'));
  252. newDate.setDate(newDate.getDate());
  253. let month = newDate.getMonth() + 1;
  254. let day = newDate.getDate();
  255. let mm = "'" + month + "'";
  256. let dd = "'" + day + "'";
  257. if (mm.length == 3) {
  258. month = "0" + month;
  259. }
  260. if (dd.length == 3) {
  261. day = "0" + day;
  262. }
  263. let hour = newDate.getHours(); //得到小时
  264. let minu = newDate.getMinutes(); //得到分钟
  265. let sec = newDate.getSeconds(); //得到秒
  266. sec = `${sec}`;
  267. minu = `${minu}`;
  268. hour = `${hour}`;
  269. if (hour.length === 1) {
  270. hour = `0${hour}`
  271. }
  272. if (minu.length === 1) {
  273. minu = `0${minu}`
  274. }
  275. if (sec.length === 1) {
  276. sec = `0${sec}`
  277. }
  278. return newDate.getFullYear() + "." + month + "." + day + ' ' + hour + ':' + minu + ':' + sec;
  279. },
  280. },
  281. }
  282. </script>
  283. <style scoped lang="scss">
  284. .detail-bottom-button {
  285. height: #{110rpx};
  286. width: #{750rpx};
  287. border-top: #{1rpx} solid #e3e3e3;
  288. .dir-left-nowrap {
  289. view {
  290. height: #{110rpx};
  291. }
  292. .but {
  293. width: #{105rpx};
  294. .text {
  295. font-size: #{20rpx};
  296. color: #707070;
  297. margin-top: #{9rpx};
  298. }
  299. }
  300. .border-left {
  301. border-right: #{1rpx} solid #e3e3e3;
  302. }
  303. .buttons {
  304. width: #{272+272rpx};
  305. }
  306. .title {
  307. width: 50%;
  308. height: #{110rpx};
  309. font-size: #{24rpx};
  310. margin: 0;
  311. }
  312. .pay {
  313. width: 50%;
  314. height: #{90rpx};
  315. line-height: #{90rpx};
  316. text-align: center;
  317. color: #ffffff;
  318. font-size: #{28rpx};
  319. }
  320. }
  321. .icon {
  322. width: #{40rpx};
  323. height: #{40rpx};
  324. margin-top: #{21rpx};
  325. }
  326. .text {
  327. color: #ffffff;
  328. }
  329. }
  330. .advance-title {
  331. width: 50%;
  332. height: #{110rpx};
  333. font-size: #{24rpx};
  334. margin: 0;
  335. }
  336. .dis-button {
  337. /*background-color: #dddddd;*/
  338. }
  339. .cart-btn {
  340. height: 90%;
  341. border-top-left-radius: #{30rpx};
  342. border-bottom-left-radius: #{30rpx};
  343. position: relative;
  344. transform: translateY(-50%);
  345. top: 50%;
  346. background: linear-gradient(to right, #A494F6, #BC8AE7, #E674B2);
  347. }
  348. .cart-btn:after {
  349. content: "";
  350. position: absolute;
  351. right: 0;
  352. height: 60%;
  353. background: #ffffff;
  354. width: 1px;
  355. top: 50%;
  356. transform: translateY(-50%);
  357. }
  358. .buy-btn {
  359. height: 90%;
  360. border-top-right-radius: #{30rpx};
  361. border-bottom-right-radius: #{30rpx};
  362. position: relative;
  363. transform: translateY(-50%);
  364. top: 50%;
  365. background: linear-gradient(to right, #E674B2, #FE3666);
  366. margin-right: 24rpx;
  367. }
  368. </style>