detail-bottom-button.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <view>
  3. <view class="bd-bottom dir-left-nowrap cross-center" v-if="active">
  4. <view @click="route_jump" class="bd-back dir-top-nowrap main-center cross-center box-grow-0">
  5. <image class="bd-icon" src="/static/image/icon/index.png"></image>
  6. <text class="bd-text">首页</text>
  7. </view>
  8. <bd-service :name="detail.name" :url="webUrl"></bd-service>
  9. <view @click="set_favorite(favorite)" class="bd-back dir-top-nowrap main-center cross-center box-grow-0" >
  10. <image class="bd-icon" :src="favorite ? '/static/image/icon/icon-favorite-active.png' : '/static/image/icon/icon-favorite.png'"></image>
  11. <text class="bd-text">收藏</text>
  12. </view>
  13. <view class="box-grow-1 bd-btn bd-oversell-btn bd-btn-color" v-if="detail.goods_num === 0">
  14. 已售罄
  15. </view>
  16. <view v-else class="box-grow-1 dir-left-nowrap">
  17. <view class="bd-btn bd-btn-half-3 bd-btn-left dir-top-nowrap main-center cross-center" :style="{'background-color': theme.background_s,'color': theme.secondary_text}">
  18. <text class="bd-line">预售截止</text>
  19. <text class="bd-line">{{getDate(end_prepayment_at)}}</text>
  20. </view>
  21. <view class="bd-btn bd-btn-half-4 bd-btn-color bd-btn-right" :style="{'background-color': !detail || detail.buy_goods_auth ? theme.background : '#999999'}" @click="set_active">
  22. 支付定金
  23. </view>
  24. </view>
  25. </view>
  26. <view v-if="!active" class="bd-bottom dir-left-nowrap">
  27. <view class="bd-btn bd-btn-half-0 dir-top-nowrap main-center cross-center" :style="{'background-color': theme.background_s,'color': theme.secondary_text}">
  28. <text class="bd-line">预售截止</text>
  29. <text class="bd-line">{{getDate(end_prepayment_at)}}</text>
  30. </view>
  31. <view class="bd-btn bd-btn-half-1 bd-btn-color" :style="{'background-color': buttonDisabled ? '#dddddd': theme.background}" @click="pay">
  32. 支付定金
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import bdService from '@/components/page-component/goods/bd-service.vue';
  39. export default {
  40. name: "detail-bottom-button",
  41. data() {
  42. return {
  43. request_time: false,
  44. once_pay: false,
  45. webUrl: '',
  46. disable: 'disable'
  47. }
  48. },
  49. components: {
  50. bdService
  51. },
  52. props: {
  53. end_prepayment_at: String,
  54. active: Boolean,
  55. favorite: Boolean,
  56. goods_id: Number,
  57. detail: Object,
  58. num: Number,
  59. theme: Object,
  60. buttonDisabled: Boolean
  61. },
  62. created() {
  63. this.webUrl = '/plugins/advance/detail/detail?id=' + this.goods_id;
  64. },
  65. methods: {
  66. set_active() {
  67. if (this.$user.isLogin() && !this.once_pay) {
  68. this.$emit('close_attr', false);
  69. } else if (!this.$user.isLogin()) {
  70. this.$user.getInfo().then(() => {
  71. }).catch(() => {
  72. });
  73. }
  74. },
  75. set_favorite(data) {
  76. if (data) {
  77. this.$request({
  78. url: this.$api.user.favorite_remove,
  79. data: {
  80. goods_id: this.goods_id,
  81. }
  82. }).then(res => {
  83. if (res.code === 0) {
  84. this.$emit('favorite', !this.favorite);
  85. } else {
  86. uni.showModal({
  87. title: '提示',
  88. content: res.msg
  89. })
  90. }
  91. })
  92. } else {
  93. this.$request({
  94. url: this.$api.user.favorite_add,
  95. data: {
  96. goods_id: this.goods_id,
  97. }
  98. }).then(res => {
  99. if (res.code === 0) {
  100. this.$emit('favorite', !this.favorite);
  101. } else {
  102. uni.showModal({
  103. title: '提示',
  104. content: res.msg
  105. })
  106. }
  107. })
  108. }
  109. },
  110. route_jump() {
  111. uni.navigateTo({
  112. url: `/pages/index/index`,
  113. });
  114. },
  115. submit(body) {
  116. this.once_pay = true;
  117. uni.showLoading({
  118. title: '生成订单中...',
  119. mask: true,
  120. });
  121. this.$emit('close_attr', true);
  122. this.get_submit(body).then(response => {
  123. this.get_token(response.data);
  124. });
  125. },
  126. pay() {
  127. if (this.buttonDisabled) return;
  128. if (this.detail.min_number > this.num) {
  129. this.$tips.showToast({
  130. title: '该商品' + this.detail.min_number + this.detail.unit + '起售',
  131. icon: 'none'
  132. });
  133. return ;
  134. }
  135. if (typeof this.detail.limit_buy !== 'undefined' && this.detail.limit_buy.status == 1 && this.detail.limit_buy.rest_number < this.num) {
  136. this.$tips.showToast({
  137. title: this.detail.limit_buy.text,
  138. icon: 'none'
  139. });
  140. return ;
  141. }
  142. let body = {
  143. goods_id: this.detail.id,
  144. goods_attr_id: 0,
  145. goods_num: `${this.num}`,
  146. advance_goods_id: this.detail.advanceGoods.id,
  147. };
  148. let attr = ``;
  149. let attr_groups = this.detail.attr_groups;
  150. for (let i = 0; i < attr_groups.length; i++) {
  151. let attr_list = attr_groups[i];
  152. for (let j = 0; j < attr_list.attr_list.length; j++) {
  153. if (attr_list.attr_list[j].active) {
  154. attr += `:${attr_list.attr_list[j].attr_id}`
  155. }
  156. }
  157. }
  158. for (let i = 0; i < this.detail.attr.length; i++) {
  159. if (this.detail.attr[i].sign_id === attr.substring(1)) {
  160. if (this.num > this.detail.attr[i].stock) {
  161. uni.showToast({
  162. title: '库存不足',
  163. icon: 'none'
  164. });
  165. return;
  166. }
  167. body.goods_attr_id = this.detail.attr[i].id;
  168. }
  169. }
  170. this.$subscribe(this.detail.template_message).then(() => {
  171. this.submit(body);
  172. }).catch(() => {
  173. this.submit(body);
  174. });
  175. },
  176. get_token(data) {
  177. this.$request({
  178. url: this.$api.advance.pay_data,
  179. method: 'post',
  180. data: {
  181. ...data
  182. },
  183. }).then(response => {
  184. if (response.code === 0) {
  185. if (response.data.hasOwnProperty('id')) {
  186. uni.hideLoading();
  187. this.$payment.pay(response.data.id).then(() => {
  188. this.once_pay = false;
  189. // 支付成功
  190. uni.navigateTo({
  191. url: `/plugins/advance/order/order`
  192. })
  193. }).catch(() => {
  194. // 支付失败
  195. this.once_pay = false;
  196. uni.navigateTo({
  197. url: `/plugins/advance/order/order`
  198. })
  199. });
  200. } else {
  201. setTimeout(() => {
  202. this.get_token(data);
  203. }, 1000);
  204. }
  205. } else {
  206. uni.hideLoading();
  207. uni.showToast({
  208. title: response.msg,
  209. icon: 'none'
  210. })
  211. }
  212. });
  213. },
  214. async get_submit(body) {
  215. const response = await this.$request({
  216. url: this.$api.advance.order_submit,
  217. method: 'post',
  218. data: {
  219. ...body,
  220. }
  221. });
  222. if (response.code === 0) {
  223. return response;
  224. } else if (response.code === 1) {
  225. uni.showModal({
  226. title: '提示',
  227. content: response.msg,
  228. success(res){
  229. if(res.cancel){
  230. this.$emit('request', this.goods_id);
  231. }else if(res.confirm){
  232. uni.navigateBack();
  233. }
  234. }
  235. });
  236. }
  237. },
  238. getDate(end_prepayment_at) {
  239. let newDate = new Date(end_prepayment_at.replace(/-/g, '/'));
  240. newDate.setDate(newDate.getDate());
  241. let month = newDate.getMonth() + 1;
  242. let day = newDate.getDate();
  243. let mm = "'" + month + "'";
  244. let dd = "'" + day + "'";
  245. if(mm.length == 3) {
  246. month = "0" + month;
  247. }
  248. if(dd.length == 3) {
  249. day = "0" + day;
  250. }
  251. let hour = newDate.getHours();//得到小时
  252. let minu = newDate.getMinutes();//得到分钟
  253. let sec = newDate.getSeconds();//得到秒
  254. sec = `${sec}`;
  255. minu = `${minu}`;
  256. hour = `${hour}`;
  257. if (hour.length === 1) {
  258. hour = `0${hour}`
  259. }
  260. if (minu.length === 1) {
  261. minu = `0${minu}`
  262. }
  263. if (sec.length === 1) {
  264. sec = `0${sec}`
  265. }
  266. return newDate.getFullYear() + "." + month + "." + day + ' ' + hour +':' + minu + ':' + sec;
  267. },
  268. },
  269. }
  270. </script>
  271. <style scoped lang="scss">
  272. .bd-bottom {
  273. width: 750upx;
  274. height: 110upx;
  275. padding: 20upx 24upx;
  276. }
  277. .bd-back {
  278. width: 66upx;
  279. height: 100%;
  280. margin-right: 20upx;
  281. }
  282. .bd-icon {
  283. width: 30upx;
  284. height: 30upx;
  285. margin-bottom: 8upx;
  286. }
  287. .bd-text {
  288. font-size: 20upx;
  289. color: #888888;
  290. line-height: 1;
  291. }
  292. .bd-btn {
  293. text-align: center;
  294. line-height: 70upx;
  295. font-size: 26upx;
  296. border-radius: 35upx;
  297. }
  298. .bd-btn-left {
  299. border-top-right-radius: 0;
  300. border-bottom-right-radius: 0;
  301. }
  302. .bd-btn-right {
  303. border-top-left-radius: 0;
  304. border-bottom-left-radius: 0;
  305. }
  306. .bd-btn-half {
  307. width: 50%;
  308. }
  309. .bd-btn-color {
  310. color: #ffffff;
  311. }
  312. .bd-oversell-btn {
  313. background-color: #CDCDCD;
  314. }
  315. .bd-line {
  316. line-height: 1.1;
  317. }
  318. .bd-btn-half-0 {
  319. width: 341upx;
  320. margin-right: 20upx
  321. }
  322. .bd-btn-half-1 {
  323. width: 341upx;
  324. }
  325. .bd-btn-half-3 {
  326. width: 65%;
  327. }
  328. .bd-btn-half-4 {
  329. width: 35%;
  330. }
  331. </style>