detail-bottom-button.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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" :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="buttons dir-left-nowrap" v-if="detail.goods_num == 0">
  21. <view class="dir-top-nowrap main-center cross-center" style="background-color: #CDCDCD;color: #fff;width: 100%;">
  22. <text>已售罄</text>
  23. </view>
  24. </view>
  25. <view v-else class="buttons dir-left-nowrap">
  26. <view class="title dir-top-nowrap main-center cross-center">
  27. <text>预售截止</text>
  28. <text>{{getDate(end_prepayment_at)}}</text>
  29. </view>
  30. <view class="pay" @click="set_active">
  31. <app-form-id>
  32. <text>
  33. 支付定金
  34. </text>
  35. </app-form-id>
  36. </view>
  37. </view>
  38. </view>
  39. <view v-if="!active" class="dir-left-nowrap">
  40. <view class="title dir-top-nowrap main-center cross-center">
  41. <text>预售截止</text>
  42. <text>{{getDate(end_prepayment_at)}}</text>
  43. </view>
  44. <view class="pay" @click="pay">
  45. <text>
  46. 支付定金
  47. </text>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. name: "detail-bottom-button",
  55. data() {
  56. return {
  57. request_time: false,
  58. once_pay: false,
  59. }
  60. },
  61. props: {
  62. end_prepayment_at: String,
  63. active: Boolean,
  64. favorite: Boolean,
  65. goods_id: Number,
  66. detail: Object,
  67. num: Number,
  68. },
  69. methods: {
  70. set_active() {
  71. if (this.$user.isLogin() && !this.once_pay) {
  72. this.$emit('close_attr', false);
  73. } else if (!this.$user.isLogin()) {
  74. this.$user.getInfo().then(() => {
  75. }).catch(() => {
  76. });
  77. }
  78. },
  79. set_favorite(data) {
  80. if (data) {
  81. this.$request({
  82. url: this.$api.user.favorite_remove,
  83. data: {
  84. goods_id: this.goods_id,
  85. }
  86. }).then(res => {
  87. if (res.code === 0) {
  88. this.$emit('favorite', !this.favorite);
  89. } else {
  90. uni.showModal({
  91. title: '提示',
  92. content: res.msg
  93. })
  94. }
  95. })
  96. } else {
  97. this.$request({
  98. url: this.$api.user.favorite_add,
  99. data: {
  100. goods_id: this.goods_id,
  101. }
  102. }).then(res => {
  103. if (res.code === 0) {
  104. this.$emit('favorite', !this.favorite);
  105. } else {
  106. uni.showModal({
  107. title: '提示',
  108. content: res.msg
  109. })
  110. }
  111. })
  112. }
  113. },
  114. route_jump() {
  115. uni.navigateTo({
  116. url: `/pages/index/index`,
  117. });
  118. },
  119. submit() {
  120. this.once_pay = true;
  121. uni.showLoading({
  122. title: '生成订单中...',
  123. mask: true,
  124. });
  125. this.$emit('close_attr', true);
  126. let body = {
  127. goods_id: this.detail.id,
  128. goods_attr_id: 0,
  129. goods_num: `${this.num}`,
  130. advance_goods_id: this.detail.advanceGoods.id,
  131. };
  132. let attr = ``;
  133. let attr_groups = this.detail.attr_groups;
  134. for (let i = 0; i < attr_groups.length; i++) {
  135. let attr_list = attr_groups[i];
  136. for (let j = 0; j < attr_list.attr_list.length; j++) {
  137. if (attr_list.attr_list[j].active) {
  138. attr += `:${attr_list.attr_list[j].attr_id}`
  139. }
  140. }
  141. }
  142. for (let i = 0; i < this.detail.attr.length; i++) {
  143. if (this.detail.attr[i].sign_id === attr.substring(1)) {
  144. body.goods_attr_id = this.detail.attr[i].id;
  145. }
  146. }
  147. this.get_submit(body).then(response => {
  148. this.get_token(response.data);
  149. });
  150. },
  151. pay() {
  152. this.$subscribe(this.detail.template_message).then(() => {
  153. this.submit();
  154. }).catch(() => {
  155. this.submit();
  156. });
  157. },
  158. get_token(data) {
  159. this.$request({
  160. url: this.$api.advance.pay_data,
  161. method: 'post',
  162. data: {
  163. ...data
  164. },
  165. }).then(response => {
  166. if (response.code === 0) {
  167. if (response.data.hasOwnProperty('id')) {
  168. uni.hideLoading();
  169. this.$payment.pay(response.data.id).then(() => {
  170. this.once_pay = false;
  171. // 支付成功
  172. uni.navigateTo({
  173. url: `/plugins/advance/order/order`
  174. })
  175. }).catch(() => {
  176. // 支付失败
  177. this.once_pay = false;
  178. uni.navigateTo({
  179. url: `/plugins/advance/order/order`
  180. })
  181. });
  182. } else {
  183. setTimeout(() => {
  184. this.get_token(data);
  185. }, 1000);
  186. }
  187. } else {
  188. uni.hideLoading();
  189. uni.showModal({
  190. title: '提示',
  191. content: response.msg,
  192. })
  193. }
  194. });
  195. },
  196. async get_submit(body) {
  197. const response = await this.$request({
  198. url: this.$api.advance.order_submit,
  199. method: 'post',
  200. data: {
  201. ...body,
  202. }
  203. });
  204. if (response.code === 0) {
  205. return response;
  206. } else if (response.code === 1) {
  207. uni.showModal({
  208. title: '提示',
  209. content: response.msg,
  210. success(res){
  211. if(res.cancel){
  212. this.$emit('request', this.goods_id);
  213. }else if(res.confirm){
  214. uni.navigateBack();
  215. }
  216. }
  217. });
  218. }
  219. },
  220. getDate(end_prepayment_at) {
  221. let newDate = new Date(end_prepayment_at.replace(/-/g, '/'));
  222. newDate.setDate(newDate.getDate());
  223. let month = newDate.getMonth() + 1;
  224. let day = newDate.getDate();
  225. let mm = "'" + month + "'";
  226. let dd = "'" + day + "'";
  227. if(mm.length == 3) {
  228. month = "0" + month;
  229. }
  230. if(dd.length == 3) {
  231. day = "0" + day;
  232. }
  233. let hour = newDate.getHours();//得到小时
  234. let minu = newDate.getMinutes();//得到分钟
  235. let sec = newDate.getSeconds();//得到秒
  236. sec = `${sec}`;
  237. minu = `${minu}`;
  238. hour = `${hour}`;
  239. if (hour.length === 1) {
  240. hour = `0${hour}`
  241. }
  242. if (minu.length === 1) {
  243. minu = `0${minu}`
  244. }
  245. if (sec.length === 1) {
  246. sec = `0${sec}`
  247. }
  248. return newDate.getFullYear() + "." + month + "." + day + ' ' + hour +':' + minu + ':' + sec;
  249. },
  250. },
  251. }
  252. </script>
  253. <style scoped lang="scss">
  254. .detail-bottom-button {
  255. height: #{110rpx};
  256. width: #{750rpx};
  257. background-color: #ffffff;
  258. border-top: #{1rpx} solid #e3e3e3;
  259. .dir-left-nowrap {
  260. view {
  261. height: #{110rpx};
  262. }
  263. .but {
  264. width: #{105rpx};
  265. .text {
  266. font-size: #{20rpx};
  267. color: #707070;
  268. margin-top: #{9rpx};
  269. }
  270. }
  271. .border-left {
  272. border-right: #{1rpx} solid #e3e3e3;
  273. }
  274. .buttons {
  275. width: #{272+272rpx};
  276. }
  277. .title {
  278. width: 50%;
  279. height: #{110rpx};
  280. background-color: #f39800;
  281. font-size: #{24rpx};
  282. color: #ffffff;
  283. }
  284. .pay {
  285. width: 50%;
  286. height: #{110rpx};
  287. line-height: #{110rpx};
  288. text-align: center;
  289. background-color: #ff4544;
  290. color: #ffffff;
  291. font-size: #{28rpx};
  292. }
  293. }
  294. .icon {
  295. width: #{40rpx};
  296. height: #{40rpx};
  297. margin-top: #{21rpx};
  298. }
  299. }
  300. </style>