app-submit-address.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <template>
  2. <view class="app-submit-address">
  3. <view class="information dir-top-nowrap main-left">
  4. <view class="express dir-left-nowrap cross-center" @click="navigateAddress"
  5. v-if="delivery === 'express' || delivery === 'city'">
  6. <view class="dir-top-nowrap content" v-if="address">
  7. <view class="top dir-left-nowrap main-between">
  8. <text class="font">收货人:{{address.name}}</text>
  9. <text class="font">{{address.mobile}}</text>
  10. </view>
  11. <view class="bottom font t-omit-two">
  12. 收货地址:{{address.province}}{{address.city}}{{address.district}}{{address.detail}}
  13. </view>
  14. </view>
  15. <view class="content font" v-else>请选择收货地址</view>
  16. <view>
  17. <image class="icon-image" src="/static/image/icon/arrow-right.png"></image>
  18. </view>
  19. </view>
  20. <view class="lifting dir-left-nowrap cross-center main-between" v-else>
  21. <input type="text" placeholder="姓名" v-model="name">
  22. <input type="number" placeholder="电话" v-model="mobile">
  23. </view>
  24. <image class="line" :src="appImg.common.address_bottom"></image>
  25. </view>
  26. <view class="delivery-method dir-left-nowrap main-between cross-center">
  27. <view>配送方式</view>
  28. <view class="dir-left-nowrap main-between method">
  29. <text v-for="(item, index) in send_type" class="item" @click="setMethod(item.value)" :key="index"
  30. :class="[`${delivery === item.value ? theme + '-background '+'text-color' : 'item-default'}`]">
  31. {{item.name}}
  32. </text>
  33. </view>
  34. </view>
  35. <view class="store-information dir-top-nowrap" v-if="delivery === 'offline'">
  36. <view class="font" v-if="Object.keys(store).length === 0">
  37. 暂无门店,请选择其他配送方式
  38. </view>
  39. <view class="font" v-if="Object.keys(store).length > 0">门店信息</view>
  40. <view class="dir-left-nowrap main-between cross-center" v-if="Object.keys(store).length > 0"
  41. @click="route_go">
  42. <view class="content dir-top-nowrap">
  43. <view class="dir-left-nowrap main-between">
  44. <view class="font">{{store.name}}</view>
  45. <view>
  46. <image class="location" src="/static/image/icon/location.png"></image>
  47. <text class="font">距您{{store.distance}}</text>
  48. </view>
  49. </view>
  50. <view class="address">
  51. {{store.address}}
  52. </view>
  53. </view>
  54. <image class="icon-image" src="/static/image/icon/arrow-right.png"></image>
  55. </view>
  56. </view>
  57. <view class="city" v-if="delivery === 'city'">
  58. <template v-if="mch.city.error">
  59. <view class="dir-left-nowrap cross-center">
  60. <view class="box-grow-1 t-omit error">{{mch.city.error}}</view>
  61. <view class="box-grow-0 btn" @click="jump()">查看配送范围</view>
  62. </view>
  63. </template>
  64. <template v-else>
  65. <view class="t-omit">发货地址:{{mch.city.address}}</view>
  66. <view class="t-omit" v-if="mch.city.explain">{{mch.city.explain}}</view>
  67. <view class="dir-left-nowrap cross-center">
  68. <view class="box-grow-1 t-omit error" style="color: #353535;">该地址在配送范围内</view>
  69. <view class="box-grow-0 btn" @click="jump()">查看配送范围</view>
  70. </view>
  71. </template>
  72. </view>
  73. <view class="safe-area-inset-bottom u-bottom-fixed">
  74. <view class="button" @click="submit" v-bind:class="[`${theme}-background`]">
  75. 确认提交
  76. </view>
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. import {mapState} from 'vuex';
  82. import appIphoneX from '../../../components/basic-component/app-iphone-x/app-iphone-x.vue';
  83. export default {
  84. props: [`theme`, `address`, `goods_id`, `user_order_id`, `store_list`, `store_index`, `send_type`, `goods`, `remark`, `mch`, `dis_send_type`, `diyForm`,
  85. `store`, `template_message_captain`],
  86. data() {
  87. return {
  88. delivery: 'express',
  89. name: '',
  90. mobile: '',
  91. send_text: '',
  92. hasCity: false,
  93. }
  94. },
  95. methods: {
  96. jump() {
  97. uni.navigateTo({
  98. url: `/pages/order-submit/map`,
  99. });
  100. },
  101. navigateAddress() {
  102. let url = '/pages/order-submit/address-pick';
  103. url += '?sign=gift&id=' + this.user_order_id + '&hasCity=' + this.hasCity;
  104. uni.navigateTo({
  105. url: url,
  106. });
  107. },
  108. setMethod(item) {
  109. this.delivery = item;
  110. this.send_text = item;
  111. this.hasCity = false;
  112. this.$emit('delivery', item);
  113. if (this.delivery === 'offline') {
  114. this.$emit('setMethod');
  115. } else if (this.delivery === 'city') {
  116. this.hasCity = true;
  117. this.$emit('city');
  118. } else if (this.delivery === 'express') {
  119. this.$emit('express');
  120. }
  121. },
  122. submit() {
  123. this.$subscribe(this.template_message_captain).then(() => {
  124. this.submission();
  125. }).catch(() => {
  126. this.submission();
  127. });
  128. },
  129. submission() {
  130. for (let i in this.goods) {
  131. const item = this.goods[i];
  132. if (!item.goods_form_validate_result) continue;
  133. if (item.goods_form_validate_result.hasError) {
  134. uni.showModal({
  135. title: '提示',
  136. content: item.goods_form_validate_result.errors[0].msg,
  137. showCancel: false,
  138. });
  139. return;
  140. }
  141. }
  142. uni.showLoading({
  143. title: '提交中'
  144. });
  145. let data = {
  146. list: [
  147. {
  148. mch_id: 0,
  149. goods_list: [],
  150. send_type: this.send_text,
  151. store_id: this.store.id,
  152. use_integral: 0,
  153. user_coupon_id: 0,
  154. remark: this.remark,
  155. order_form: this.diyForm,
  156. }
  157. ],
  158. address_id: this.address && this.address.id ? this.address.id : 0,
  159. address: {
  160. name: this.name,
  161. mobile: this.mobile,
  162. }
  163. };
  164. for (let i = 0; i < this.goods.length; i++) {
  165. let good = {
  166. id: this.goods[i].goods_id,
  167. attr: [],
  168. num: this.goods[i].num,
  169. cat_id: 0,
  170. goods_attr_id: this.goods[i].goods_attr_id,
  171. cart_id: 0,
  172. user_order_id: this.user_order_id,
  173. form_data: this.goods[i].form_data,
  174. };
  175. let attr = [];
  176. let attr_list = this.goods[i].goods_info;
  177. for (let j = 0; j < attr_list.length; j++) {
  178. attr.push({
  179. attr_id: attr_list[j].attr_id,
  180. attr_group_id: attr_list[j].attr_group_id,
  181. })
  182. }
  183. good.attr = attr;
  184. data.list[0].goods_list.push(good);
  185. }
  186. this.$request({
  187. url: this.$api.gift.convert,
  188. method: 'post',
  189. data: {
  190. form_data: JSON.stringify(data)
  191. },
  192. }).then(res => {
  193. if (res.code === 0) {
  194. this.pay_data(res.data);
  195. } else {
  196. uni.hideLoading();
  197. uni.showModal({
  198. title: '提示',
  199. content: res.msg,
  200. })
  201. }
  202. });
  203. },
  204. route_go() {
  205. uni.navigateTo({
  206. url: `/pages/order-submit/store-pick?plugin=gift`
  207. })
  208. },
  209. pay_data(data) {
  210. this.$request({
  211. url: this.$api.order.pay_data,
  212. method: 'post',
  213. data: {
  214. ...data,
  215. }
  216. }).then(res => {
  217. if (res.code === 0) {
  218. if (res.data.hasOwnProperty('id')) {
  219. let id = res.data.id;
  220. if (this.mch.express_price == 0) {
  221. this.$request({
  222. url: this.$api.payment.get_payments,
  223. method: 'get',
  224. data: {
  225. id: id,
  226. }
  227. }).then(res => {
  228. if (res.code === 0) {
  229. this.$request({
  230. url: this.$api.payment.pay_data,
  231. method: 'get',
  232. data: {
  233. id: id,
  234. pay_type: 'balance',
  235. }
  236. }).then(res => {
  237. if (res.code === 0) {
  238. this.$request({
  239. url: this.$api.payment.pay_buy_balance,
  240. data: {
  241. id: id,
  242. }
  243. }).then(res => {
  244. if (res.code === 0) {
  245. uni.hideLoading();
  246. // uni.redirectTo({
  247. // url: `/plugins/gift/order/order`,
  248. // })
  249. uni.redirectTo({
  250. url: `/pages/order-submit/pay-result?payment_order_union_id=${id}&order_page_url=${encodeURIComponent('/plugins/gift/order/order')}`,
  251. });
  252. } else {
  253. uni.hideLoading();
  254. uni.showModal({
  255. title: '提示',
  256. content: res.msg,
  257. })
  258. }
  259. })
  260. } else {
  261. uni.hideLoading();
  262. uni.showModal({
  263. title: '提示',
  264. content: res.msg,
  265. })
  266. }
  267. })
  268. } else {
  269. uni.hideLoading();
  270. uni.showModal({
  271. title: '提示',
  272. content: res.msg,
  273. })
  274. }
  275. })
  276. } else {
  277. this.$payment.pay(id).then(msg => {
  278. // 支付成功
  279. uni.hideLoading();
  280. uni.redirectTo({
  281. url: `/plugins/gift/order/order`,
  282. })
  283. }).catch(msg => {
  284. // 支付失败
  285. uni.hideLoading();
  286. uni.redirectTo({
  287. url: `/plugins/gift/order/order`,
  288. })
  289. });
  290. }
  291. } else {
  292. setTimeout(() => {
  293. this.pay_data(data);
  294. }, 1000);
  295. }
  296. } else {
  297. uni.hideLoading();
  298. uni.showModal({
  299. title: '提示',
  300. content: res.msg,
  301. })
  302. }
  303. })
  304. }
  305. },
  306. computed: {
  307. ...mapState({
  308. appImg: state => state.mallConfig.__wxapp_img,
  309. }),
  310. },
  311. watch: {
  312. send_type: {
  313. handler(v) {
  314. if (v.length === 0) return;
  315. for (let i = 0; i < v.length; i++) {
  316. if (this.dis_send_type === v[0].value) {
  317. this.delivery = v[0].value;
  318. this.send_text = v[0].value;
  319. if (v[0].value === 'city') {
  320. this.hasCity = true;
  321. }
  322. }
  323. }
  324. },
  325. immediate: true
  326. }
  327. },
  328. components: {
  329. 'app-iphone-x': appIphoneX,
  330. }
  331. }
  332. </script>
  333. <style lang="scss" scoped>
  334. @import '../css/gift.scss';
  335. .icon-image {
  336. width: #{12upx};
  337. height: #{22upx};
  338. }
  339. .information {
  340. background-color: #ffffff;
  341. }
  342. .app-submit-address {
  343. width: 100%;
  344. .express {
  345. .content {
  346. width: #{660upx};
  347. margin-right: #{28upx};
  348. }
  349. padding: #{32upx 24upx};
  350. .top {
  351. margin-bottom: #{22upx};
  352. }
  353. .font {
  354. font-size: #{32upx};
  355. line-height: 1;
  356. color: #353535;
  357. }
  358. .bottom {
  359. line-height: #{36upx};
  360. }
  361. }
  362. .line {
  363. width: 100%;
  364. height: #{8upx};
  365. }
  366. }
  367. .delivery-method {
  368. font-size: #{32upx};
  369. width: 100%;
  370. margin-top: #{24upx};
  371. background-color: #ffffff;
  372. height: #{120upx};
  373. padding: #{0 24upx};
  374. .method {
  375. .item {
  376. width: #{170upx};
  377. height: #{56upx};
  378. border-radius: #{30upx};
  379. line-height: #{56upx};
  380. text-align: center;
  381. margin-right: #{10upx};
  382. }
  383. .item-default {
  384. background-color: #f7f7f7;
  385. }
  386. }
  387. }
  388. .button {
  389. height: #{100upx};
  390. line-height: #{100upx};
  391. font-size: #{36upx};
  392. color: #ffffff;
  393. text-align: center;
  394. }
  395. .lifting {
  396. padding: #{0 24upx};
  397. width: 100%;
  398. height: #{100upx};
  399. input {
  400. width: 50%;
  401. color: #353535;
  402. font-size: #{32upx};
  403. }
  404. }
  405. /*门店信息*/
  406. .store-information {
  407. width: 100%;
  408. padding: #{32upx 24upx 32upx 24upx};
  409. background-color: #ffffff;
  410. border-top: #{1upx} solid #e2e2e2;
  411. .content {
  412. padding: #{32upx 40upx 32upx 0};
  413. width: #{662upx};
  414. }
  415. .font {
  416. color: #353535;
  417. font-size: #{32upx};
  418. line-height: 1;
  419. }
  420. .location {
  421. width: #{22upx};
  422. height: #{26upx};
  423. margin-right: #{8upx};
  424. }
  425. .address {
  426. color: #999999;
  427. font-size: #{28upx};
  428. line-height: 1;
  429. margin-top: #{20upx};
  430. }
  431. }
  432. .city {
  433. padding: #{32rpx 24rpx};
  434. font-size: #{28upx};
  435. background-color: #ffffff;
  436. margin-bottom: #{20rpx};
  437. .btn {
  438. padding: #{10rpx} #{20rpx};
  439. border-radius: #{100rpx};
  440. border: #{1rpx} solid #cccccc;
  441. font-size: $uni-font-size-general-two;
  442. color: $uni-general-color-one;
  443. }
  444. .error {
  445. color: #ff4544;
  446. margin-right: #{24rpx};
  447. }
  448. }
  449. .text-color {
  450. color: #ffffff;
  451. }
  452. .u-bottom-fixed {
  453. position: fixed;
  454. bottom: 0;
  455. left: 0;
  456. width: 100%;
  457. z-index: 1500;
  458. background-color: #ffffff;
  459. }
  460. </style>