create-order.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <template>
  2. <view class="container order clearfix" :style="{paddingBottom :isIphoneX ? '170rpx' : '134rpx'}">
  3. <!-- 地址选择 -->
  4. <choice-address ref="choiceAddress" v-if="isAddress" :addressData="addressData"></choice-address>
  5. <!-- 商品 -->
  6. <goodsList ref='goods' v-if="isRequest" :goodsData="goodsData" @handleGoodList="handChangeInputGoodsList"></goodsList>
  7. <!-- 发票信息 -->
  8. <seller-invoice ref="invoice"
  9. v-if="isRequest"
  10. :invoiceDatas="invoiceData"
  11. @handleChoiceaInvoice="handleChoiceaInvoiceData">
  12. </seller-invoice>
  13. <!-- 运费 -->
  14. <seller-freight ref="freight"
  15. v-if="isRequest"
  16. :freightDatas="freightData"
  17. @handleChoiceaFreight="handleChoiceaFreightData"
  18. @showFreightAlert="handFreightAlertShow">
  19. </seller-freight>
  20. <freight-alert v-if="isfreightTip" ref="csPhone"></freight-alert>
  21. <!-- 余额抵扣 -->
  22. <view class="invoice-balance" v-show="!rechargeGoods">
  23. <view class="balabce-t">
  24. <view class="balabce-t-le">余额抵扣</view>
  25. <view class="balabce-t-ri">
  26. <view class="money">
  27. <text>可用余额:</text>
  28. <text>¥{{userMoney | NumFormat}}</text>
  29. </view>
  30. <view class="checkbox-box" v-if="userMoney!==0">
  31. <button class="checkbox iconfont"
  32. hover-class="btn-hover"
  33. @click.stop="checkedBalabce"
  34. :class="[ischecked ?'icon-xuanze':'icon-weixuanze']"
  35. >
  36. </button>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="balabce-b" :class="{'balabce-b--hide':!ischecked}">
  41. <view class="balabce-b-text animation" :style="{'transform':ischecked?'translateY(0)':'translateY(-50%)','-webkit-transform':ischecked?'translateY(0)':'translateY(-50%)'}">
  42. <text>当前使用:¥{{deductMoney | NumFormat}},剩余:¥{{surplusMoney | NumFormat}}</text>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 底部 -->
  47. <view class="footer" :style="{paddingBottom :isIphoneX ? '68rpx' : '0rpx'}">
  48. <view class="footer-le">
  49. <view class="footer-count">
  50. <text>共{{allCount}}件商品</text>
  51. </view>
  52. <view class="footer-price">
  53. <view class="sum-none" v-if="totalFullReduction>0">
  54. <text class="money-sign">¥</text>
  55. <text class="money">{{ totalOriginalPrice | NumFormat }}</text>
  56. <text class="money-reduced">减<text>¥{{ totalFullReduction | NumFormat}}</text></text>
  57. </view>
  58. <view class="sum" :class="totalFullReduction == 0 ? 'none' : ''">总价:<text class="price">¥{{payAllPrice | NumFormat}}</text></view>
  59. </view>
  60. </view>
  61. <view class="footer-submit" @click.stop="orderSubmitMit">
  62. <view class="btn" :class="isSubLoading ? 'disabled' : ''">提交订单</view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import choiceAddress from '@/components/cm-module/creatOrder/address'
  69. import goodsList from '@/components/cm-module/creatOrder/goodsList'
  70. import sellerInvoice from '@/components/cm-module/creatOrder/sellerInvoice'
  71. import sellerFreight from '@/components/cm-module/creatOrder/sellerFreight'
  72. import freightAlert from '@/components/cm-module/modelAlert/freightAlert.vue'
  73. import { mapState } from 'vuex'
  74. export default {
  75. components:{
  76. choiceAddress,
  77. goodsList,
  78. sellerInvoice,
  79. sellerFreight,
  80. freightAlert,
  81. },
  82. data() {
  83. return {
  84. isSubLoading:false,
  85. orderID:0,
  86. userId:'',
  87. storeId:'',
  88. productIds:'', //获取上一级页面商品信息
  89. productCount:'', //获取上一级页面商品数量
  90. classifyIDS:'', //获取上一级页面商品分类
  91. serviceProviderId:'', //协销ID
  92. submitState:'', //提交状态
  93. allCount:1, //订单提交总数量
  94. totalOriginalPrice:0, //订单总原价(划线部分)
  95. totalFullReduction:0, //满减金额
  96. payAllPrice:0.00, //订单提交总金额
  97. allPrice:0.00, //订单总金额
  98. addressId:'', //地址ID
  99. townId:'', //区ID
  100. isRequest:false, //是否加载完成渲染子组件
  101. isFreight:false, //是否加载完成渲染子组件
  102. isAddress:false, //是否加载完成地址
  103. isfreightTip:false, //控制邮费弹窗
  104. ischecked:false, //是否勾选余额
  105. addressData:{}, //初始化地址信息
  106. goodsData:[], //初始化商品信息
  107. invoiceData:{type:0}, //初始化发票信息
  108. freightData:{}, //邮费数据
  109. orderInfo:[], //提交的商品信息
  110. payInfo:{}, //订单信息
  111. isIphoneX:this.$store.state.isIphoneX,
  112. clauseId:0,
  113. productsList:[],
  114. // 余额抵扣
  115. userMoney:0, //可用余额
  116. deductMoney:0, //当前使用金额
  117. surplusMoney:0, //剩余金额
  118. balanceDeductionFlag:0
  119. }
  120. },
  121. onLoad(option){//商品数据
  122. let data = JSON.parse(option.data);
  123. this.allPrice = data.data.allPrice;
  124. this.allCount = data.data.allCount;
  125. this.payAllPrice = this.totalPrice;
  126. this.storeId = data.data.storeId
  127. this.productIds = data.data.productID
  128. console.log(this.allCount)
  129. this.getInitCrearOrder();
  130. },
  131. filters:{
  132. NumFormat(value) {//处理金额
  133. return Number(value).toFixed(2);
  134. },
  135. },
  136. computed:{
  137. ...mapState(['userInfo'])
  138. },
  139. methods: {
  140. getInitCrearOrder(option){//确认订单初始化信息
  141. // let params ={userId:this.userId,productIds:this.productIds}
  142. let params ={organizeId:this.userInfo.organizeId, storeId:this.storeId ,productIds:this.productIds}
  143. this.OrderService.QueryOrderConfirm(params)
  144. .then(response =>{
  145. let data = response.data
  146. let productIds = []
  147. this.isRequest = true
  148. this.goodsData = data.shopList
  149. this.totalFullReduction = data.totalFullReduction
  150. this.totalOriginalPrice = data.totalFullReduction + data.totalPrice
  151. this.allPrice = this.payAllPrice = data.totalPrice
  152. this.userMoney = data.userMoney
  153. })
  154. .catch(error =>{
  155. this.$util.msg(error.msg,2000)
  156. })
  157. },
  158. //获取邮费信息
  159. getFreightData(){
  160. let params ={
  161. storeId:this.storeId,
  162. productIds:this.productIds,
  163. totalPrice:this.allPrice,
  164. townId:this.addressData.townId
  165. }
  166. this.OrderService.GetOrderPostage(params).then(response =>{
  167. this.isFreight = true
  168. this.freightData = response.data
  169. if(response.data.freePostFlag== 1){
  170. this.payAllPrice = this.allPrice+response.data.freight
  171. }else{
  172. this.payAllPrice = this.allPrice
  173. }
  174. })
  175. },
  176. //获取地址信息
  177. getAddressData(){
  178. this.UserService.QueryAddressList({pageNum:1,pageSize:1,storeId:this.storeId})
  179. .then(response =>{
  180. this.isAddress = true
  181. this.addressData = {}
  182. if(response.data.list != ''){
  183. this.addressId = response.data.list[0].addressId;
  184. this.townId = response.data.list[0].townId;
  185. this.addressData = response.data.list[0];
  186. // this.getFreightData()
  187. }else{
  188. this.addressData = this.addressData;
  189. }
  190. })
  191. },
  192. handChangeInputGoodsList(data){//对应供应商的留言信息
  193. this.goodsData = data;
  194. },
  195. handleChoiceaInvoiceData(data){//获取发票信息
  196. this.invoiceData = data
  197. },
  198. handleChoiceaFreightData(data){//获取运费信息
  199. if(data.freePostFlag == '1'){
  200. this.freightData = data
  201. this.payAllPrice = this.allPrice+parseInt(data.freight)
  202. this.attributePallPrice()
  203. }else{
  204. this.freightData = data
  205. this.payAllPrice = this.allPrice
  206. this.attributePallPrice()
  207. }
  208. },
  209. attributePallPrice(){//计算价格
  210. if(this.freightData.freePostFlag == 1 || this.freightData.freePostFlag == '1'){
  211. this.attributeHashfreight(this.freightData.freight)
  212. }else{
  213. this.attributeNofreight()
  214. }
  215. },
  216. attributeNofreight(){//计算没有邮费的支付价格
  217. if(this.ischecked){
  218. if(this.userMoney>this.payAllPrice){
  219. this.payAllPrice = 0.00
  220. this.deductMoney = this.allPrice //勾选后使用抵余额
  221. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  222. }else{
  223. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  224. this.deductMoney = this.userMoney //勾选后使用抵余额
  225. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  226. }
  227. }else{
  228. this.payAllPrice = this.allPrice;
  229. this.deductMoney = 0.00;
  230. this.surplusMoney = this.userMoney;
  231. }
  232. },
  233. attributeHashfreight(freight){//计算需要邮费的支付价格
  234. this.payAllPrice = this.allPrice+parseInt(freight)//计算不包邮的价格 总价等于商品价格+邮费
  235. },
  236. checkedBalabce(){//勾选使用余额
  237. if(this.userMoney > 0){
  238. this.ischecked = !this.ischecked
  239. if(this.ischecked){
  240. this.balanceDeductionFlag =1
  241. this.attributePallPrice()
  242. }else{
  243. this.payAllPrice = this.allPrice
  244. this.balanceDeductionFlag = 2
  245. }
  246. }else{
  247. return
  248. }
  249. },
  250. orderSubmitMit(){//提交订单
  251. if(this.isSubLoading){ return; }
  252. if(this.addressId == ''){
  253. this.$util.msg('请先添加收货地址~',2000)
  254. return
  255. }
  256. // 处理商品信息及留言
  257. this.orderInfo = this.goodsData.map(el => {
  258. let productInfo = [];
  259. el.productList.forEach(item => {
  260. productInfo.push({
  261. productId: item.productId,
  262. productNum: item.productCount,
  263. productType: item.productType ? Number(item.productType) : 0,
  264. presentNum: 0,
  265. })
  266. })
  267. return { shopId: el.shopId, note: el.note?el.note:'', productInfo: productInfo }
  268. })
  269. //订单信息
  270. this.payInfo = {
  271. orderShouldPayFee:this.payAllPrice.toFixed(2),//提交的总价
  272. balancePayFlag:this.balanceDeductionFlag,//余额抵扣的状态
  273. freight:-1,//邮费
  274. freePostFlag:-1//运费形式
  275. }
  276. console.log(this.payInfo)
  277. let params = {
  278. // clubUserId:this.userId,
  279. storeId:this.storeId,
  280. organizeId:this.userInfo.organizeId,
  281. addressId:this.addressId, //地址ID
  282. orderInfo:this.orderInfo, //商品信息
  283. payInfo:this.payInfo, //订单信息
  284. orderInvoice:this.invoiceData //发票信息
  285. }
  286. this.isSubLoading = true;
  287. this.OrderService.CreatedOrderSubmit(params).then(response =>{
  288. const payResult = response.data
  289. // 提交订单并支付成功(余额抵扣)
  290. if(payResult.code === '1'){
  291. this.$util.msg('订单提交成功',2000,true,'success')
  292. this.submitState = 'success'
  293. setTimeout(()=>{
  294. this.isSubLoading = false;
  295. this.$api.redirectTo(`/pages/user/order/success?orderId=${payResult.orderId}&type=${this.submitState}`)
  296. },2000)
  297. }else if(payResult.code === '2'){
  298. this.$util.msg('订单提交成功',2000,true,'success')
  299. this.submitState ='confirm'
  300. setTimeout(()=>{
  301. this.isSubLoading = false;
  302. // this.$api.redirectTo(`/pages/user/order/success?orderId=${payResult.orderId}&type=${this.submitState}`)
  303. this.$api.redirectTo(`/pages/user/order/order-payment?orderId=${payResult.orderId}&type=payfirm`)
  304. },2000)
  305. }else{
  306. this.$util.msg('订单提交失败,请新提交',2000);
  307. setTimeout(()=>{
  308. this.isSubLoading = false;
  309. }, 2000)
  310. }
  311. }).catch(error =>{
  312. this.$util.msg(error.msg,2000);
  313. setTimeout(()=>{
  314. this.isSubLoading = false;
  315. }, 2000)
  316. })
  317. },
  318. handFreightAlertShow(){//显示邮费弹窗
  319. this.isfreightTip = true;
  320. },
  321. hideFreight(){//关闭邮费弹窗
  322. this.isfreightTip = false;
  323. },
  324. },
  325. onShow() {
  326. // this.addressId = ''
  327. let pages = getCurrentPages();
  328. let currPage = pages[pages.length-1];
  329. if(currPage.data.select =='select'){
  330. this.isAddress = true
  331. let SelectData = uni.getStorageSync('selectAddress');
  332. this.addressId = SelectData.addressId;
  333. this.addressData = SelectData
  334. // this.getFreightData()
  335. }else{
  336. this.getAddressData()
  337. }
  338. }
  339. }
  340. </script>
  341. <style lang="scss">
  342. page {
  343. height: auto;
  344. background:#F7F7F7;
  345. }
  346. .btn-hover{
  347. background: #FFFFFF;
  348. }
  349. .animation{
  350. /* transition: transform 0.3s ease;*/
  351. transition-property: transform;
  352. transition-duration: 0.3s;
  353. transition-timing-function: ease;
  354. }
  355. .invoice-freight{
  356. width: 702rpx;
  357. padding: 0 24rpx;
  358. height: 86rpx;
  359. line-height: 86rpx;
  360. font-size: $font-size-28;
  361. color: $text-color;
  362. background: #FFFFFF;
  363. float: left;
  364. font-weight: bold;
  365. .freight-left{
  366. float: left;
  367. .icon-yunfeishuoming{
  368. height: 100%;
  369. padding: 0 15rpx;
  370. color: $color-system;
  371. font-weight: normal;
  372. }
  373. }
  374. .freight-right{
  375. float: right;
  376. color: #2A81FF;
  377. }
  378. }
  379. .invoice-balance{
  380. width: 702rpx;
  381. height: auto;
  382. padding:0 24rpx;
  383. background: #FFFFFF;
  384. float: left;
  385. margin-bottom: 24rpx;
  386. .balabce-t{
  387. width: 100%;
  388. height: 86rpx;
  389. line-height: 86rpx;
  390. font-size: $font-size-28;
  391. color: $text-color;
  392. float: left;
  393. .balabce-t-le{
  394. float: left;
  395. font-weight: bold;
  396. }
  397. .balabce-t-ri{
  398. float: right;
  399. display: flex;
  400. align-items: center;
  401. .money{
  402. display: flex;
  403. float: left;
  404. }
  405. .checkbox-box{
  406. display: flex;
  407. width: 60rpx;
  408. float: left;
  409. height: 100%;
  410. font-size: $font-size-24;
  411. .checkbox{
  412. width: 40rpx;
  413. text-align: right;
  414. box-sizing: border-box;
  415. text-align: center;
  416. text-decoration: none;
  417. border-radius: 0;
  418. -webkit-tap-highlight-color: transparent;
  419. overflow: hidden;
  420. color: #ff2a2a;
  421. padding: 5rpx;
  422. }
  423. .icon-weixuanze{
  424. color: $color-system;
  425. }
  426. }
  427. }
  428. }
  429. .balabce-b{
  430. width: 100%;
  431. float: left;
  432. overflow: hidden;
  433. .balabce-b-text{
  434. width: 100%;
  435. line-height: 58rpx;
  436. font-size: $font-size-24;
  437. color: #FF2A2A;
  438. text-align: right;
  439. float: right;
  440. }
  441. &.balabce-b--hide {
  442. padding: 0 0;
  443. height: 0px;
  444. line-height: 0px;
  445. }
  446. }
  447. }
  448. .footer{
  449. position: fixed;
  450. left: 0;
  451. bottom: 0;
  452. z-index: 995;
  453. display: flex;
  454. align-items: center;
  455. width: 100%;
  456. height: 110rpx;
  457. line-height: 110rpx;
  458. justify-content: space-between;
  459. font-size: $font-size-28;
  460. background-color: #FFFFFF;
  461. z-index: 998;
  462. color: $text-color;
  463. .footer-le{
  464. width:570rpx;
  465. height:100%;
  466. float: left;
  467. }
  468. .footer-count{
  469. float: left;
  470. padding-left: 24rpx;
  471. width:170rpx;
  472. box-sizing: border-box;
  473. font-size: $font-size-26;
  474. }
  475. .footer-price{
  476. float: right;
  477. text-align: right;
  478. color: $text-color;
  479. padding: 10rpx 20rpx 10rpx 0;
  480. box-sizing: border-box;
  481. width: 385rpx;
  482. .sum-none{
  483. width: 100%;
  484. height: 45rpx;
  485. line-height: 45rpx;
  486. color: $text-color;
  487. float: left;
  488. text-align: right;
  489. .money{
  490. font-size: $font-size-26;
  491. color: #999999;
  492. text-decoration: line-through;
  493. }
  494. .money-sign{
  495. font-size: $font-size-26;
  496. color: #999999;
  497. text-decoration: line-through;
  498. }
  499. .money-reduced{
  500. margin-left: 10rpx;
  501. font-size: $font-size-26;
  502. color:$color-system;
  503. }
  504. }
  505. .sum{
  506. width: 100%;
  507. height: 45rpx;
  508. line-height: 45rpx;
  509. float: left;
  510. &.none{
  511. height: 90rpx;
  512. line-height: 90rpx;
  513. }
  514. .price{
  515. font-size: $font-size-32;
  516. color: #FF2A2A;
  517. }
  518. }
  519. }
  520. .footer-submit{
  521. display:flex;
  522. align-items:center;
  523. justify-content: center;
  524. width: 200rpx;
  525. height: 100%;
  526. box-sizing: border-box;
  527. padding: 15rpx 5rpx;
  528. .btn{
  529. width: 100%;
  530. height: 100%;
  531. color: #FFFFFF;
  532. background:#ff2a2a;
  533. font-size: $font-size-26;
  534. text-align: center;
  535. line-height: 80rpx;
  536. border-radius: 40rpx;
  537. &.disabled{
  538. background: #e4e8eb;
  539. color: #999999;
  540. }
  541. }
  542. }
  543. }
  544. .Rebate{
  545. width: 702rpx;
  546. height: auto;
  547. padding: 0 24rpx;
  548. background: #FFFFFF;
  549. float: left;
  550. margin-bottom: 24rpx;
  551. margin-bottom: 24rpx;
  552. line-height: 86rpx;
  553. .rebate-title{
  554. float: left;
  555. font-weight: bold;
  556. color: #333333;
  557. font-size: $font-size-28;
  558. }
  559. .iconfont{
  560. float: right;
  561. color: #b2b2b2;
  562. font-size: 40rpx;
  563. &.icon-yixuanze{
  564. color: $color-system;
  565. }
  566. }
  567. }
  568. </style>