create-order.vue 16 KB

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