create-order.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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.toFixed(2)}}</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.toFixed(2)}},剩余:¥{{surplusMoney.toFixed(2)}}</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. <text>总价:<text class="price">¥{{payAllPrice.toFixed(2)}}</text></text>
  56. </view>
  57. </view>
  58. <view class="footer-submit" @click.stop="orderSubmitMit">提交订单</view>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import choiceAddress from '@/components/cm-module/creatOrder/choiceAddress'
  64. import goodsList from '@/components/cm-module/creatOrder/goodsList'
  65. import invoiceTent from '@/components/cm-module/creatOrder/invoiceTent'
  66. import freight from '@/components/cm-module/creatOrder/freight'
  67. import freightAlert from '@/components/cm-module/modelAlert/freightAlert'
  68. import modalLayer from "@/components/modal-layer"
  69. import { queryAddressList } from "@/api/cart.js"
  70. import { createOrderInfo,createOrderSubmit,getOrderPostage } from "@/api/order.js"
  71. export default {
  72. components:{
  73. choiceAddress,
  74. goodsList,
  75. invoiceTent,
  76. freight,
  77. freightAlert,
  78. modalLayer
  79. },
  80. data() {
  81. return {
  82. modallayer:false,
  83. orderID:0,
  84. productIds:'', //获取上一级页面商品信息
  85. productCount:'', //获取上一级页面商品数量
  86. classifyIDS:'', //获取上一级页面商品分类
  87. userID:'', //用户ID
  88. cartType:'', //购买类型(1购物车提交,2直接购买提交)
  89. submitState:'', //提交状态
  90. balanceDeductionFlag:2, //勾选余额的状态(1使用,2不使用)
  91. allCount:1, //订单提交总数量
  92. payAllPrice:0.00, //订单提交总金额
  93. allPrice:0.00, //订单总金额
  94. surplusMoney:0.00, //显示勾选后的剩余抵扣
  95. userMoney:0.00, //显示可使用余额
  96. deductMoney:0.00, //显示已使用的余额
  97. addressID:'', //地址ID
  98. townID:'', //区ID
  99. isRequest:false, //是否加载完成渲染子组件
  100. isFreight:false, //是否加载完成渲染子组件
  101. isAddress:false, //是否加载完成地址
  102. isfreightTip:false, //控制邮费弹窗
  103. ischecked:false, //是否勾选余额
  104. hanldFreePostFlag:'', //邮费状态
  105. hanldFreight:'', //邮费
  106. addressData:{}, //初始化地址信息
  107. goodsData:[], //初始化商品信息
  108. invoiceData:{type:0}, //初始化发票信息
  109. freightData:{}, //邮费数据
  110. orderInfo:[], //提交的商品信息
  111. payInfo:{}, //订单信息
  112. rechargeGoods:null, //判断订单里有定金商品或者充值商品时,余额抵扣部分不显示
  113. isIphoneX:this.$store.state.isIphoneX
  114. }
  115. },
  116. onLoad(option){//商品数据
  117. let data = JSON.parse(option.data);
  118. this.allPrice = data.data.allPrice;
  119. this.allCount = data.data.allCount;
  120. this.payAllPrice = this.allPrice;
  121. if(option.type =='prodcut'){
  122. this.cartType = 2
  123. this.productCount = data.data.productCount
  124. this.productIds = data.data.productID
  125. }else{
  126. this.cartType = 1
  127. this.productCount = data.data.productCount
  128. this.productIds = data.data.productID
  129. }
  130. this.$api.getStorage().then((resolve) =>{
  131. this.userID = resolve.userID
  132. this.getInitCrearOrder(option);
  133. })
  134. },
  135. methods: {
  136. getInitCrearOrder(option){//获取订单商品信息
  137. let params ={userId:this.userID,count:this.productCount,productIds:this.productIds}
  138. createOrderInfo(params).then(response =>{
  139. let resData = response.data
  140. this.isRequest = true
  141. this.goodsData = resData.shopList
  142. this.userMoney = resData.userMoney
  143. this.rechargeGoods = resData.rechargeGoods
  144. }).catch(error =>{
  145. this.$util.msg(error.msg,2000)
  146. })
  147. },
  148. getFreightData(){//获取邮费信息
  149. let params ={
  150. userId:this.userID,
  151. productIds:this.productIds,
  152. totalPrice:this.allPrice,
  153. townId:this.addressData.townID
  154. }
  155. getOrderPostage(params).then(response =>{
  156. this.isFreight = true
  157. this.freightData = response.data
  158. this.hanldFreePostFlag = response.data.freePostFlag
  159. this.hanldFreight = response.data.freight
  160. if(this.hanldFreePostFlag == 1){
  161. this.payAllPrice = this.allPrice + response.data.freight
  162. this.attributePallPrice()
  163. }else{
  164. this.payAllPrice = this.allPrice
  165. this.attributePallPrice()
  166. }
  167. })
  168. },
  169. getAddressData(){//获取地址信息
  170. this.$api.getStorage().then((resolve) => {
  171. queryAddressList({pageNum:1,pageSize:1,userID:resolve.userID}).then(response =>{
  172. this.isAddress = true
  173. this.addressData = {}
  174. if(response.data.results != ''){
  175. this.addressID = response.data.results[0].addressID;
  176. this.townID = response.data.results[0].townID;
  177. this.addressData = response.data.results[0];
  178. this.getFreightData()
  179. }else{
  180. this.addressData = this.addressData;
  181. }
  182. })
  183. })
  184. },
  185. handChangeInputGoodsList(data){//对应供应商的留言信息
  186. this.goodsData = data;
  187. },
  188. handleChoiceaInvoiceData(data){//获取发票信息
  189. this.invoiceData = data
  190. },
  191. hanldFreightFn(data){//显示邮费弹窗
  192. switch(data){
  193. case 1:
  194. this.hanldFreight = this.freightData.freight
  195. this.hanldFreePostFlag = data
  196. this.payAllPrice =this.allPrice + this.hanldFreight
  197. this.attributePallPrice()
  198. break
  199. case -1:
  200. this.hanldFreight = 0
  201. this.hanldFreePostFlag = data
  202. this.payAllPrice = this.allPrice
  203. this.attributePallPrice()
  204. break
  205. }
  206. },
  207. checkedBalabce(){//勾选使用余额
  208. if(this.userMoney > 0){
  209. this.ischecked = !this.ischecked
  210. if(this.ischecked){
  211. this.balanceDeductionFlag =1
  212. this.attributePallPrice()
  213. }else{
  214. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  215. this.payAllPrice = this.allPrice+parseInt(this.freightData.freight)
  216. }else{
  217. this.payAllPrice = this.allPrice
  218. }
  219. this.balanceDeductionFlag = 2
  220. }
  221. }else{
  222. return
  223. }
  224. },
  225. attributePallPrice(){//计算价格
  226. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  227. this.attributeHashfreight(this.freightData.freight)
  228. }else{
  229. this.attributeNofreight()
  230. }
  231. },
  232. attributeNofreight(){//计算没有邮费的支付价格
  233. if(this.ischecked){
  234. if(this.userMoney>this.payAllPrice){
  235. this.payAllPrice = 0.00
  236. this.deductMoney = this.allPrice //勾选后使用抵余额
  237. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  238. }else{
  239. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  240. this.deductMoney = this.userMoney //勾选后使用抵余额
  241. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  242. }
  243. }else{
  244. this.payAllPrice = this.allPrice;
  245. this.deductMoney = 0.00;
  246. this.surplusMoney = this.userMoney;
  247. }
  248. },
  249. attributeHashfreight(freight){//计算需要邮费的支付价格
  250. this.payAllPrice = this.allPrice+parseInt(freight)//计算不包邮的价格 总价等于商品价格+邮费
  251. if(this.ischecked){
  252. if(this.userMoney>this.payAllPrice){ //余额大于支付金额
  253. this.payAllPrice =0.00
  254. this.deductMoney = this.allPrice+parseInt(freight) //勾选后使用抵余额
  255. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  256. }else{
  257. this.payAllPrice = this.allPrice+parseInt(freight) - this.userMoney //勾选后的总价
  258. this.deductMoney = this.userMoney //勾选后使用抵余额
  259. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  260. }
  261. }else{
  262. this.payAllPrice = this.allPrice+parseInt(freight)
  263. this.deductMoney = 0.00
  264. this.surplusMoney = this.userMoney
  265. }
  266. },
  267. orderSubmitMit(){//提交订单
  268. if(this.addressID == ''){
  269. this.$util.msg('请先添加收货地址~',2000)
  270. return
  271. }
  272. this.orderInfo = this.goodsData.map(el => {
  273. let productInfo = [];
  274. el.productsList.forEach(item => {
  275. productInfo.push({
  276. productId:item.productID,
  277. productNum:item.productCount,
  278. presentNum:0
  279. })
  280. })
  281. return {shopId:el.shopID,note:el.note?el.note:'',productInfo:productInfo}
  282. })
  283. //订单信息
  284. this.payInfo = {
  285. clauseId:0,//条款(暂时保留)
  286. orderShouldPayFee:this.payAllPrice.toFixed(2),//提交的总价
  287. balancePayFlag:this.balanceDeductionFlag,//余额抵扣的状态
  288. freight:parseInt(this.hanldFreight).toFixed(2),//邮费
  289. freePostFlag:parseInt(this.hanldFreePostFlag)//运费形式
  290. }
  291. let param = {
  292. orderSource:6,
  293. clubUserId:this.userID,
  294. cartType:this.cartType,
  295. addressId:this.addressID,
  296. orderInfo:this.orderInfo,
  297. payInfo:this.payInfo, //订单信息
  298. orderInvoice:this.invoiceData
  299. }
  300. // console.log(param)
  301. this.modalLayer = true;
  302. createOrderSubmit({'params':JSON.stringify(param)}).then(response =>{
  303. if(response.code === 1){
  304. this.submitState ='success'
  305. let data = {orderID:response.data.orderID}
  306. this.$api.navigateTo(`/pages/user/order/success?data=${JSON.stringify({data:data})}`)
  307. }else if(response.code === 2){
  308. this.submitState ='confirm'
  309. this.$util.msg('订单提交成功',3000,true,'success')
  310. setTimeout(()=>{
  311. this.$api.redirectTo(`/pages/user/order/order-payment?type=${this.submitState}&orderID=${response.data.orderID}`)
  312. },3000)
  313. }else{
  314. this.$util.msg(response.msg,3000);
  315. }
  316. }).catch(error =>{})
  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. .order{
  356. padding-bottom: 134rpx;
  357. }
  358. .invoice-freight{
  359. width: 702rpx;
  360. padding: 0 24rpx;
  361. height: 86rpx;
  362. line-height: 86rpx;
  363. font-size: $font-size-28;
  364. color: $text-color;
  365. background: #FFFFFF;
  366. float: left;
  367. font-weight: bold;
  368. .freight-left{
  369. float: left;
  370. .icon-yunfeishuoming{
  371. height: 100%;
  372. padding: 0 15rpx;
  373. color: $color-system;
  374. font-weight: normal;
  375. }
  376. }
  377. .freight-right{
  378. float: right;
  379. color: #2A81FF;
  380. }
  381. }
  382. .invoice-balance{
  383. width: 702rpx;
  384. height: auto;
  385. padding:0 24rpx;
  386. background: #FFFFFF;
  387. float: left;
  388. margin-top: 24rpx;
  389. margin-bottom: 24rpx;
  390. .balabce-t{
  391. width: 100%;
  392. height: 86rpx;
  393. line-height: 86rpx;
  394. font-size: $font-size-28;
  395. color: $text-color;
  396. float: left;
  397. .balabce-t-le{
  398. float: left;
  399. font-weight: bold;
  400. }
  401. .balabce-t-ri{
  402. float: right;
  403. display: flex;
  404. align-items: center;
  405. .money{
  406. display: flex;
  407. float: left;
  408. }
  409. .checkbox-box{
  410. display: flex;
  411. width: 60rpx;
  412. float: left;
  413. height: 100%;
  414. font-size: $font-size-24;
  415. .checkbox{
  416. width: 40rpx;
  417. text-align: right;
  418. box-sizing: border-box;
  419. text-align: center;
  420. text-decoration: none;
  421. border-radius: 0;
  422. -webkit-tap-highlight-color: transparent;
  423. overflow: hidden;
  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:550rpx;
  465. height:100%;
  466. float: left;
  467. }
  468. .footer-count{
  469. float: left;
  470. padding-left: 24rpx;
  471. font-weight: bold;
  472. }
  473. .footer-price{
  474. float: right;
  475. text-align: right;
  476. color: $text-color;
  477. font-weight: bold;
  478. padding-right: 24rpx;
  479. .price{
  480. font-size: $font-size-32;
  481. color: #FF2A2A;
  482. }
  483. }
  484. .footer-submit{
  485. display:flex;
  486. align-items:center;
  487. justify-content: center;
  488. width: 200rpx;
  489. height: 100%;
  490. color: #FFFFFF;
  491. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  492. }
  493. }
  494. </style>