address.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <app-layout>
  3. <view class="address" v-if="loading">
  4. <app-submit-address
  5. v-bind:previewData="previewData"
  6. v-bind:theme="theme"
  7. v-bind:address="address"
  8. v-bind:name="name"
  9. v-bind:mobile="mobile"
  10. v-bind:goods_id="goods_id"
  11. v-bind:user_order_id="user_order_id"
  12. v-bind:store_list="store_list"
  13. v-bind:store_index="store_index"
  14. v-on:setMethod="setMethod"
  15. v-bind:send_type="send_type"
  16. v-bind:goods="goods"
  17. v-bind:remark="remark"
  18. v-bind:store="store"
  19. v-bind:mch="mch"
  20. v-bind:dis_send_type="dis_send_type"
  21. v-bind:diyForm="diyForm"
  22. v-on:city="city"
  23. v-on:delivery="delivery"
  24. v-on:express="express"
  25. :template_message_captain="template_message_captain"
  26. ></app-submit-address>
  27. <view class="some-good">
  28. <view class="goods dir-left-nowrap" v-for="(item, index) in goods" :key="index">
  29. <image :src="item.cover_pic" class="pic"></image>
  30. <view class="content dir-top-nowrap main-left">
  31. <text class="name t-omit-two">
  32. {{item.name}}
  33. </text>
  34. <text class="attr t-omit">
  35. {{item.attr}}
  36. </text>
  37. <text class="number">×{{item.num}}</text>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="freight dir-left-nowrap main-between cross-center" v-if="mch.express_price != 0">
  42. <text class="text">运费</text>
  43. <text :class="theme+'-color'">¥{{mch.express_price}}</text>
  44. </view>
  45. <view v-if="mch.order_form && mch.order_form.status == '1'">
  46. <app-diy-form
  47. v-bind:title="mch.order_form.name"
  48. v-bind:list="mch.order_form.value"
  49. v-bind:sign="mchIndex"
  50. label-position="top"
  51. v-on:input="diyFormInput"
  52. v-bind:show-scroll-btn="mch.order_form.show_scroll"
  53. ></app-diy-form>
  54. </view>
  55. <view class="leave-message" v-else-if="mch.show_remark !== false && mch.has_goods_form !== true">
  56. <textarea class="textarea" placeholder-class="place" v-model="remark" placeholder="备注留言"></textarea>
  57. </view>
  58. <template v-if="mch.has_goods_form">
  59. <view style="padding: 24rpx; color: #666666">自定义表单</view>
  60. <view v-for="(goodsItem, goodsIndex) in mch.goods_list"
  61. :key="goodsIndex"
  62. v-if="goodsItem.form && !goodsItem.form.same_form"
  63. style="margin-bottom: 20rpx">
  64. <view class="goods-list some-good" v-if="mch.diff_goods_form_count !== 1">
  65. <view v-for="(subGoodsItem, subGoodsIndex) in mch.goods_list"
  66. :key="subGoodsIndex"
  67. v-if="subGoodsItem.form && subGoodsItem.form.id == goodsItem.form.id"
  68. class="goods dir-left-nowrap">
  69. <image class="pic"
  70. :src="subGoodsItem.goods_attr.pic_url ? subGoodsItem.goods_attr.pic_url : subGoodsItem.cover_pic"></image>
  71. <view class="box-grow-1 content">
  72. <view class="goods-name">{{subGoodsItem.name}}</view>
  73. <view class="dir-left-wrap attr-list">
  74. <view v-for="(attrItem,attrIndex) in subGoodsItem.attr_list"
  75. :key="attrIndex"
  76. class="attr-item attr">
  77. {{attrItem.attr_group_name}}:{{attrItem.attr_name}}
  78. </view>
  79. </view>
  80. <view class="dir-left-nowrap">
  81. <view class="box-grow-1 goods-num number">×{{subGoodsItem.num}}</view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. <app-diy-form
  87. :list="goodsItem.form.value"
  88. @input="handleGoodsFormInput"
  89. @validate="handleGoodsFormValidate"
  90. :sign="`0,${goodsIndex},${goodsItem.form.id}`"></app-diy-form>
  91. </view>
  92. </template>
  93. <!-- 空白格 -->
  94. <view class="page-width empty">
  95. <app-empty-bottom
  96. backgroundColor="#f7f7f7"
  97. v-bind:height="Number(110)"
  98. ></app-empty-bottom>
  99. </view>
  100. </view>
  101. </app-layout>
  102. </template>
  103. <script>
  104. import appSubimtAddress from './app-submit-address.vue';
  105. import {mapState} from 'vuex';
  106. import appEmptyBottom from '../../../components/basic-component/app-empty-bottom/app-empty-bottom.vue';
  107. import AppDiyForm from "../../../components/page-component/app-diy-form/app-diy-form";
  108. export default {
  109. name: 'address',
  110. data() {
  111. return {
  112. previewData: {
  113. hasCity: false
  114. },
  115. address_id: '',
  116. address: {},
  117. goods_id: -1,
  118. user_order_id: 0,
  119. goods: [],
  120. store_list: [],
  121. store_index: 0,
  122. send_type: [],
  123. remark: '',
  124. store: {},
  125. mch: {},
  126. send_data: null,
  127. deli: '',
  128. loading: false,
  129. dis_send_type: '',
  130. diyForm: [],
  131. template_message_captain: []
  132. }
  133. },
  134. onLoad(options) { this.$commonLoad.onload(options);
  135. this.goods_id = options.goods_id;
  136. this.user_order_id = options.id;
  137. let url = '';
  138. if (options.status == 2) {
  139. url = this.$api.gift.join_detail
  140. } else if (options.status == 1) {
  141. url = this.$api.gift.win_detail;
  142. }
  143. this.$request({
  144. url: url,
  145. data: {
  146. user_order_id: options.id,
  147. }
  148. }).then(res => {
  149. for (let i in res.data.detail.detail) {
  150. res.data.detail.detail[i].form_data = null;
  151. }
  152. this.template_message_captain = res.data.template_message_captain;
  153. this.goods = res.data.detail.detail;
  154. let data = {
  155. list: [
  156. {
  157. mch_id: 0,
  158. goods_list: [],
  159. use_integral: 0,
  160. user_coupon_id: 0,
  161. distance: 0,
  162. remark: '',
  163. order_form: [],
  164. }
  165. ],
  166. address_id: 0
  167. };
  168. for (let i = 0; i < this.goods.length; i++) {
  169. let good = {
  170. id: this.goods[i].goods_id,
  171. attr: [],
  172. num: this.goods[i].num,
  173. cat_id: 0,
  174. goods_attr_id: this.goods[i].goods_attr_id,
  175. cart_id: 0,
  176. user_order_id: options.id,
  177. };
  178. let attr = [];
  179. let attr_list = this.goods[i].goods_info;
  180. for (let j = 0; j < attr_list.length; j++) {
  181. attr.push({
  182. attr_id: attr_list[j].attr_id,
  183. attr_group_id: attr_list[j].attr_group_id,
  184. })
  185. }
  186. good.attr = attr;
  187. data.list[0].goods_list.push(good);
  188. }
  189. this.send_data = data;
  190. this.$request({
  191. url: this.$api.gift.preview,
  192. method: 'post',
  193. data: {
  194. form_data: JSON.stringify(data)
  195. },
  196. }).then(res => {
  197. if (res.code === 0) {
  198. this.send_type = res.data.mch_list[0].delivery.send_type_list;
  199. this.dis_send_type = res.data.mch_list[0].delivery.send_type;
  200. this.mch = res.data.mch_list[0];
  201. this.address = res.data.address;
  202. this.loading = true;
  203. if (this.send_type[0].value === 'offline') {
  204. // this.store = res.data.mch_list[0].store;
  205. this.setMethod();
  206. }
  207. } else {
  208. uni.showModal({
  209. title: '提示',
  210. content: res.msg,
  211. success: function () {
  212. uni.navigateBack();
  213. }
  214. })
  215. }
  216. })
  217. });
  218. },
  219. onShow() {
  220. if (this.$store.state.gift.address_id && !this.$validation.isEmpty(this.send_data)) {
  221. let data = this.send_data;
  222. data.list[0].send_type = this.deli;
  223. data.list[0].address_id = this.$store.state.gift.address_id;
  224. data.address_id = this.$store.state.gift.address_id;
  225. this.$request({
  226. url: this.$api.gift.preview,
  227. method: 'post',
  228. data: {
  229. form_data: JSON.stringify(data)
  230. },
  231. }).then(res => {
  232. if (res.code === 0) {
  233. this.send_type = res.data.mch_list[0].delivery.send_type_list;
  234. this.mch = res.data.mch_list[0];
  235. this.address = res.data.address;
  236. if (this.deli === 'city') {
  237. this.address = this.mch.address;
  238. }
  239. } else {
  240. uni.showModal({
  241. title: '提示',
  242. content: res.msg,
  243. success: function () {
  244. uni.navigateBack();
  245. }
  246. });
  247. }
  248. })
  249. }
  250. if (this.$store.state.gift.store_id) {
  251. for (let i = 0; i < this.store_list.length; i++) {
  252. if (this.store_list[i].id === this.$store.state.gift.store_id) {
  253. this.store = this.store_list[i];
  254. }
  255. }
  256. }
  257. },
  258. methods: {
  259. delivery(data) {
  260. this.deli = data;
  261. },
  262. setMethod() {
  263. let _this = this;
  264. // #ifdef MP
  265. uni.getLocation({
  266. type: 'wgs84',
  267. success: function (res) {
  268. _this.$request({
  269. url: _this.$api.order.store_list,
  270. data: {
  271. latitude: res.latitude,
  272. longitude: res.longitude,
  273. goods_id: _this.goods_id,
  274. }
  275. }).then(res => {
  276. _this.store_list = res.data.list;
  277. _this.store = res.data.list[0];
  278. })
  279. }
  280. });
  281. // #endif
  282. // #ifdef H5
  283. this.$jwx.getLocation({
  284. success: function (res) {
  285. _this.$request({
  286. url: _this.$api.order.store_list,
  287. data: {
  288. latitude: res.latitude,
  289. longitude: res.longitude,
  290. goods_id: _this.goods_id,
  291. }
  292. }).then(res => {
  293. _this.store_list = res.data.list;
  294. _this.store = res.data.list[0];
  295. });
  296. }
  297. });
  298. // #endif
  299. },
  300. city() {
  301. let data = this.send_data;
  302. data.list[0].send_type = 'city';
  303. if (this.address && this.address.type !== 1) {
  304. data.list[0].address_id = this.address.id;
  305. }
  306. this.$request({
  307. url: this.$api.gift.preview,
  308. method: 'post',
  309. data: {
  310. form_data: JSON.stringify(data)
  311. },
  312. }).then(res => {
  313. this.send_type = res.data.mch_list[0].delivery.send_type_list;
  314. this.mch = res.data.mch_list[0];
  315. this.address = res.data.mch_list[0].address;
  316. if (this.address && this.address.type !== 1) {
  317. this.address = null;
  318. }
  319. })
  320. },
  321. express() {
  322. let data = this.send_data;
  323. data.list[0].send_type = 'express';
  324. if (this.address) {
  325. data.list[0].address_id = this.address.id;
  326. }
  327. this.$request({
  328. url: this.$api.gift.preview,
  329. method: 'post',
  330. data: {
  331. form_data: JSON.stringify(data)
  332. },
  333. }).then(res => {
  334. this.send_type = res.data.mch_list[0].delivery.send_type_list;
  335. this.mch = res.data.mch_list[0];
  336. this.address = res.data.mch_list[0].address;
  337. })
  338. },
  339. diyFormInput({data}) {
  340. this.diyForm = data;
  341. },
  342. handleGoodsFormInput(data, sign) {
  343. const signArr = sign.split(',');
  344. const goodsIndex = parseInt(signArr[1]);
  345. const result = [];
  346. for (let i in data) {
  347. result[i] = {
  348. key: data[i].key,
  349. label: data[i].name,
  350. value: data[i].value,
  351. required: data[i].is_required,
  352. };
  353. }
  354. this.goods[goodsIndex].form_data = result;
  355. },
  356. handleGoodsFormValidate(result, sign) {
  357. const signArr = sign.split(',');
  358. const goodsIndex = parseInt(signArr[1]);
  359. this.goods[goodsIndex].goods_form_validate_result = result;
  360. },
  361. },
  362. computed: {
  363. ...mapState('gift', {
  364. theme: state => state.theme,
  365. }),
  366. },
  367. components: {
  368. 'app-submit-address': appSubimtAddress,
  369. 'app-empty-bottom': appEmptyBottom,
  370. 'app-diy-form': AppDiyForm,
  371. },
  372. }
  373. </script>
  374. <style scoped lang="scss">
  375. @import '../css/gift';
  376. /* 商品页面 */
  377. .address {
  378. position: absolute;
  379. width: 100%;
  380. min-height: 100%;
  381. background-color: #f7f7f7;
  382. }
  383. .some-good {
  384. background: #ffffff;
  385. padding: #{28upx 24upx 0 24upx};
  386. overflow: hidden;
  387. .goods {
  388. height: #{156upx};
  389. margin-bottom: #{28upx};
  390. .pic {
  391. width: #{156upx};
  392. height: #{156upx};
  393. margin-right: #{24upx};
  394. }
  395. .content {
  396. width: #{522upx};
  397. height: #{156upx};
  398. .name {
  399. font-size: #{32upx};
  400. color: #353535;
  401. line-height: #{38upx};
  402. }
  403. .attr {
  404. color: #999999;
  405. font-size: #{24upx};
  406. line-height: 1;
  407. margin-top: #{18upx};
  408. }
  409. .number {
  410. color: #999999;
  411. font-size: #{24upx};
  412. line-height: 1;
  413. margin-top: #{18upx}
  414. }
  415. }
  416. }
  417. }
  418. .leave-message {
  419. margin-top: #{24upx};
  420. height: #{100upx};
  421. line-height: #{100upx};
  422. padding: #{18upx 24upx};
  423. background-color: #ffffff;
  424. .textarea {
  425. font-size: #{32upx};
  426. width: 100%;
  427. height: 100%;
  428. line-height: #{64upx};
  429. padding: 0;
  430. }
  431. .place {
  432. line-height: #{64upx};
  433. }
  434. }
  435. .freight {
  436. width: #{750upx};
  437. background-color: #ffffff;
  438. padding: #{0 24upx};
  439. margin-top: #{20upx};
  440. height: #{88upx};
  441. text {
  442. font-size: #{32upx};
  443. }
  444. .text {
  445. color: #353535;
  446. }
  447. }
  448. </style>