index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <template>
  2. <view>
  3. <view class="top">
  4. <image src="../../../static/images/bg.png" mode="widthFix"></image>
  5. <view class="title">无忧快捷发货</view>
  6. </view>
  7. <view class="platform">
  8. <view class="step step1">1.选择数据来源平台</view>
  9. <radio-group @change="changePlatform">
  10. <view class="list">
  11. <view :class="item.id == platformId ? 'item active' : 'item'" v-for="(item,index) in platform" :key="index">
  12. <text :class="'iconfont icon-'+item.code"></text>
  13. {{item.name}}
  14. <radio :value="item.id.toString()" />
  15. </view>
  16. </view>
  17. </radio-group>
  18. </view>
  19. <view class="address">
  20. <view class="step">2.填写收货地址</view>
  21. <view class="form">
  22. <view class="input">
  23. 订单号<input type='text' placeholder='请输入订单号(可不填)' placeholder-class='placeholder' v-model="delivery.out_order_id"></input>
  24. </view>
  25. <view class="input">
  26. 收货人<input type='text' placeholder='请输入收货人姓名' placeholder-class='placeholder' v-model="delivery.name"></input>
  27. </view>
  28. <view class="input">
  29. 手机号<input type='number' placeholder='请输入手机号码' placeholder-class='placeholder' v-model="delivery.mobile"></input>
  30. </view>
  31. <textarea placeholder-style="color:#ccc;font-size:28rpx;" placeholder="示例: 浙江省 台州市 椒江区 市府大道12号" v-model="delivery.address" @blur="getExtraFreight"/>
  32. </view>
  33. </view>
  34. <view class="gift">
  35. <view class="step">3.选择赠送礼品</view>
  36. <view class="warehouse">
  37. <view v-for="(item,index) in warehouse" :key="index" :class='item.id == warehouseId ? "on" : ""' @click='changeWarehouse(index)'>
  38. {{item.name}}
  39. </view>
  40. </view>
  41. <radio-group @change="changeProduct" v-if="productList.length > 0">
  42. <view class="product" v-for="(item , index) in productList" :key="index">
  43. <radio :value="index.toString()" :checked="index == current"/>
  44. <image :src="item.img"></image>
  45. <view class="info">
  46. <view>{{item.title}}</view>
  47. <view class="price">¥{{item.price}}</view>
  48. <view class="text">
  49. <view>{{item.wget}}kg/件</view>
  50. <view>库存{{item.count}}</view>
  51. </view>
  52. </view>
  53. </view>
  54. </radio-group>
  55. <view class="noProduct" v-else>暂无产品</view>
  56. </view>
  57. <view class="bottom">
  58. <view>
  59. <view>礼品金额:<text>¥{{price}}</text>,运费:<text>¥{{freight}}</text></view>
  60. <view v-if="extraFreight">偏远地区加钱:<text>¥{{extraFreight}}</text></view>
  61. <view class="total">总价:<text>¥{{total}}</text></view>
  62. </view>
  63. <button @click="submit">提交订单</button>
  64. </view>
  65. <wyb-popup ref="payOrder" type="bottom" height="500" width="400" radius="8">
  66. <view class="popup">
  67. <view class="title">
  68. 支付订单<text class="iconfont icon-guanbi" @click='close'></text>
  69. </view>
  70. <view>支付单号:{{payData.order_id}}</view>
  71. <view>商品名称:{{payData.title}}</view>
  72. <view>发货数量:{{payData.count}}</view>
  73. <view>支付金额:¥{{payData.all_price}}</view>
  74. <view>支付方式:
  75. <view class="payway">
  76. <text class="iconfont icon-yuezhifu"></text>余额支付
  77. <image src="../../../static/images/icon.png" mode="widthFix"></image>
  78. </view>
  79. <view class="balance">账户余额:¥{{payData.user_money}}<text @click="go">充值</text></view>
  80. </view>
  81. <button @click="pay(payData.order_id)">立即支付</button>
  82. </view>
  83. </wyb-popup>
  84. </view>
  85. </template>
  86. <script>
  87. import {
  88. mapGetters
  89. } from "vuex";
  90. import {
  91. toLogin
  92. } from '@/libs/login.js';
  93. import {
  94. platformList,
  95. ApiWarehouse,
  96. productList,
  97. submitOrder,
  98. payOrder,
  99. balancePay
  100. } from '@/api/api.js';
  101. import wybPopup from '@/components/wyb-popup/wyb-popup.vue'
  102. export default {
  103. components: {
  104. wybPopup
  105. },
  106. data() {
  107. return {
  108. platform: [],
  109. platformId: '',
  110. warehouse: [],
  111. warehouseData: [],
  112. warehouseId: '',
  113. warehouseIndex: '',
  114. expId: '',
  115. productList: [],
  116. productId: '',
  117. current: -1,
  118. delivery: {
  119. out_order_id: '',
  120. name: '',
  121. mobile: '',
  122. address: '',
  123. shop_name: ''
  124. },
  125. price: 0,
  126. freight: 0,
  127. extraFreight: 0,
  128. total: 0,
  129. payData: {}
  130. }
  131. },
  132. computed: mapGetters(['isLogin']),
  133. onLoad() {
  134. if (this.isLogin) {
  135. this.getPlatform();
  136. this.getWarehouse();
  137. this.getProductList();
  138. }else{
  139. toLogin();
  140. }
  141. },
  142. methods: {
  143. getPlatform: function() {
  144. let that = this;
  145. platformList().then(res => {
  146. that.platform = res.data.list;
  147. });
  148. },
  149. getWarehouse: function() {
  150. let that = this;
  151. ApiWarehouse().then(res => {
  152. that.warehouse = res.data;
  153. that.warehouseData = res.data;
  154. });
  155. },
  156. getProductList: function() {
  157. let that = this;
  158. productList({
  159. warehouse: that.warehouseId,
  160. countType: 1,
  161. pageSize: 5
  162. }).then(res => {
  163. that.productList = res.data.list;
  164. });
  165. },
  166. changePlatform:function(evt) {
  167. let that = this;
  168. that.platformId = evt.target.value;
  169. that.tabWarehouse(that.platformId);
  170. that.warehouseId = that.warehouse[0].id;
  171. that.warehouseIndex = 0;
  172. if(that.warehouse[0].expCode.length > 0){
  173. that.expId = that.warehouse[0].expCode[0].id;
  174. that.freight = parseFloat(that.warehouse[0].expCode[0].money);
  175. that.total = that.price + that.freight;
  176. }
  177. that.getProductList();
  178. that.getExtraFreight();
  179. },
  180. //选择平台后切换仓库
  181. tabWarehouse:function(id){
  182. var data = [];
  183. //判断仓库
  184. for (var i in this.warehouseData) {
  185. var idsAr = this.warehouseData[i].platform_ids.split(',');
  186. if(idsAr.indexOf(id) >= 0) {
  187. data.push(this.warehouseData[i]);
  188. }
  189. }
  190. this.warehouse = data;
  191. },
  192. changeWarehouse:function(index) {
  193. let that = this;
  194. if (!that.platformId) return that.$util.Tips({
  195. title: '请先选择数据来源平台'
  196. });
  197. that.warehouseId = that.warehouse[index].id;
  198. that.warehouseIndex = index;
  199. if(that.warehouse[index].expCode.length > 0){
  200. that.expId = that.warehouse[index].expCode[0].id;
  201. that.freight = parseFloat(that.warehouse[index].expCode[0].money);
  202. }else{
  203. that.freight = 0;
  204. }
  205. that.current = -1;
  206. that.productId = '';
  207. that.price = 0;
  208. that.getProductList();
  209. that.getExtraFreight();
  210. },
  211. changeProduct:function(evt) {
  212. let that = this;
  213. if (!that.platformId) return that.$util.Tips({
  214. title: '请先选择数据来源平台'
  215. });
  216. let index = evt.target.value;
  217. that.current = index;
  218. that.productId = that.productList[index].id;
  219. that.price = parseFloat(that.productList[index].price);
  220. that.total = (parseFloat(that.price) + parseFloat(that.freight) + parseFloat(that.extraFreight)).toFixed(2);
  221. },
  222. //偏远地区加钱
  223. getExtraFreight:function () {
  224. let that = this;
  225. if(that.delivery.address.indexOf("北京") != -1){
  226. that.extraFreight = parseFloat(that.warehouse[that.warehouseIndex].beijing);
  227. }
  228. if(that.delivery.address.indexOf("上海") != -1){
  229. that.extraFreight = parseFloat(that.warehouse[that.warehouseIndex].shanghai);
  230. }
  231. if(that.delivery.address.indexOf("青海") != -1){
  232. that.extraFreight = parseFloat(that.warehouse[that.warehouseIndex].qinghai);
  233. }
  234. that.total = (parseFloat(that.price) + parseFloat(that.freight) + parseFloat(that.extraFreight)).toFixed(2);
  235. },
  236. submit: function() {
  237. let that = this;
  238. if (!that.platformId) return that.$util.Tips({
  239. title: '请选择数据来源平台'
  240. });
  241. if (!that.delivery.name) return that.$util.Tips({
  242. title: '请输入收货人姓名'
  243. });
  244. if (!that.delivery.mobile) return that.$util.Tips({
  245. title: '请输入手机号码'
  246. });
  247. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.delivery.mobile))) return that.$util.Tips({
  248. title: '请输入正确的手机号码'
  249. });
  250. if (!that.delivery.address) return that.$util.Tips({
  251. title: '请输入收货地址'
  252. });
  253. if(that.delivery.address.indexOf("新疆") != -1 || that.delivery.address.indexOf("西藏") != -1) return that.$util.Tips({
  254. title: '新疆西藏地区不发货'
  255. });
  256. if (!that.productId) return that.$util.Tips({
  257. title: '请选择赠送礼品'
  258. });
  259. let orderAr = [];
  260. orderAr.push(that.delivery);
  261. submitOrder({
  262. platformId: that.platformId,
  263. warehouseId: that.warehouseId,
  264. proId: that.productId,
  265. expId: that.expId,
  266. orderAr: orderAr,
  267. mono: '',
  268. extraFreight: that.extraFreight
  269. }).then(res => {
  270. payOrder({'order_id':res.data.order_id}).then(res => {
  271. that.payData = res.data;
  272. that.$refs.payOrder.show();
  273. });
  274. }).catch(err => {
  275. that.$util.Tips({
  276. title: err
  277. });
  278. });
  279. },
  280. close() {
  281. this.$refs.payOrder.hide();
  282. },
  283. pay: function(order_id) {
  284. let that = this;
  285. balancePay({'order_id':order_id}).then(res => {
  286. that.$util.Tips({
  287. title:res.data.msg
  288. },{
  289. tab: 2,
  290. url: '/pages/users/order/index?status=1'
  291. })
  292. }).catch(err => {
  293. that.$util.Tips({
  294. title: err
  295. });
  296. });
  297. },
  298. go() {
  299. uni.navigateTo({
  300. url: `/pages/users/recharge/index`
  301. })
  302. }
  303. }
  304. }
  305. </script>
  306. <style scoped lang="scss">
  307. .top{
  308. background: #ff5c00;
  309. position: relative;
  310. image{
  311. width:100%;
  312. }
  313. .title{
  314. position: absolute;
  315. top:50rpx;
  316. left:30rpx;
  317. font-size: 46rpx;
  318. color:#fff;
  319. }
  320. }
  321. .step{
  322. font-weight: 600;
  323. color:#262626;
  324. margin-bottom: 20rpx;
  325. }
  326. .platform{
  327. background: #fff;
  328. width:700rpx;
  329. margin: -200rpx 25rpx 0 25rpx;
  330. padding: 30rpx 10rpx;
  331. border-radius: 20rpx;
  332. position: relative;
  333. z-index: 100;
  334. .step1{
  335. padding-left: 10rpx;
  336. }
  337. .list{
  338. display: flex;
  339. flex-wrap: wrap;
  340. .item{
  341. width:320rpx;
  342. margin: 10rpx;
  343. border: 1px solid #ddd;
  344. border-radius: 4rpx;
  345. display: flex;
  346. align-items: center;
  347. padding: 0 15rpx;
  348. line-height: 92rpx;
  349. .iconfont{
  350. font-size: 45rpx;
  351. margin-right: 15rpx;
  352. }
  353. .icon-taobao{color:#FF780A;font-size: 50rpx;}
  354. .icon-t1688{color:#FF5400;font-size: 65rpx;margin-right: 0;}
  355. .icon-jd{color:#E0251B;}
  356. .icon-pdd{color:#E12E24;}
  357. .icon-othen{color:#488EFF;}
  358. radio{
  359. flex-grow:1;
  360. text-align: right;
  361. }
  362. }
  363. .active{
  364. border: 1px solid #ff5c00;
  365. }
  366. }
  367. }
  368. .address{
  369. background: #fff;
  370. width:700rpx;
  371. margin:20rpx 25rpx 0 25rpx;
  372. padding: 30rpx 20rpx;
  373. border-radius: 10rpx;
  374. .form{
  375. .input{
  376. display: flex;
  377. padding: 20rpx 0;
  378. border-bottom: 1px solid #eee;
  379. input{
  380. margin-left: 40rpx;
  381. font-size: 28rpx;
  382. .placeholder{
  383. color:#ccc;
  384. font-size: 28rpx;
  385. }
  386. }
  387. }
  388. textarea{
  389. height:120rpx;
  390. padding-top: 20rpx;
  391. font-size: 28rpx;
  392. }
  393. }
  394. }
  395. .gift{
  396. background: #fff;
  397. width:700rpx;
  398. margin:20rpx 25rpx 140rpx 25rpx;
  399. padding: 30rpx 20rpx;
  400. border-radius: 10rpx;
  401. .warehouse{
  402. display: flex;
  403. flex-wrap: wrap;
  404. margin: 30rpx 0 10rpx 0;
  405. view{
  406. padding: 10rpx 7rpx;
  407. margin-bottom: 10rpx;
  408. border: 1rpx solid #eee;
  409. }
  410. view:nth-child(odd){
  411. margin-right: 10rpx;
  412. }
  413. .on{
  414. border: 1rpx solid #ff5c00;
  415. color: #ff5c00;
  416. }
  417. }
  418. .product{
  419. display: flex;
  420. margin-top: 20rpx;
  421. radio{
  422. line-height: 160rpx;
  423. margin-right: 10rpx;
  424. }
  425. image{
  426. width:160rpx;
  427. height:160rpx;
  428. }
  429. .info{
  430. padding-left: 20rpx;
  431. flex-grow: 1;
  432. .price{
  433. color: #f5222d;
  434. font-size: 32rpx;
  435. font-weight: bold;
  436. margin-top: 40rpx;
  437. }
  438. .text{
  439. display: flex;
  440. justify-content:space-between;
  441. font-size: 24rpx;
  442. color:#666;
  443. }
  444. }
  445. }
  446. .noProduct{
  447. text-align: center;
  448. height:120rpx;
  449. line-height: 120rpx;
  450. }
  451. }
  452. .bottom{
  453. background: #fff;
  454. position: absolute;
  455. bottom: 100rpx;
  456. display: flex;
  457. justify-content: space-between;
  458. align-items: center;
  459. width:100%;
  460. height:120rpx;
  461. padding: 0 32rpx;
  462. text{
  463. color:#ea312b;
  464. }
  465. .total{
  466. display: flex;
  467. align-items: center;
  468. text{
  469. font-size: 36rpx;
  470. font-weight: 600;
  471. }
  472. }
  473. button{
  474. width:220rpx;
  475. height:80rpx;
  476. line-height: 80rpx;
  477. background: #ff5c00;
  478. color:#fff;
  479. font-size: 32rpx;
  480. border-radius: 50rpx;
  481. }
  482. }
  483. .popup{
  484. padding: 30rpx;
  485. view{
  486. display: flex;
  487. align-items: center;
  488. flex-wrap: wrap;
  489. margin-bottom: 10rpx;
  490. }
  491. .title{
  492. justify-content: space-between;
  493. font-size: 32rpx;
  494. margin-bottom: 20rpx;
  495. }
  496. .payway{
  497. display: flex;
  498. position: relative;
  499. border: 1rpx solid #ff5c00;
  500. border-radius: 8rpx;
  501. width: 200rpx;
  502. height: 60rpx;
  503. line-height: 60rpx;
  504. padding-left: 10rpx;
  505. .iconfont{
  506. color:#ff5c00;
  507. margin-right: 5rpx;
  508. }
  509. image{
  510. width:40rpx;
  511. position: absolute;
  512. bottom: 0;
  513. right: 0;
  514. }
  515. }
  516. .balance{
  517. margin-left: 140rpx;
  518. color:#aaa;
  519. text{
  520. border: 1rpx solid #ff5c00;
  521. color:#ff5c00;
  522. margin-left: 30rpx;
  523. padding: 3rpx 20rpx;
  524. border-radius: 30rpx;
  525. }
  526. }
  527. button{
  528. background: #ff5c00;
  529. color:#fff;
  530. border-radius: 40rpx;
  531. font-size: 32rpx;
  532. line-height: 80rpx;
  533. margin-top: 30rpx;
  534. }
  535. }
  536. </style>