create-order.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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">
  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. isIphoneX:this.$store.state.isIphoneX
  113. }
  114. },
  115. onLoad(option){//商品数据
  116. let data = JSON.parse(option.data);
  117. this.allPrice = data.data.allPrice;
  118. this.allCount = data.data.allCount;
  119. this.payAllPrice = this.allPrice;
  120. if(option.type =='prodcut'){
  121. this.cartType = 2
  122. this.productCount = data.data.productCount
  123. this.productIds = data.data.productID
  124. }else{
  125. this.cartType = 1
  126. this.productCount = data.data.productCount
  127. this.productIds = data.data.productID
  128. }
  129. this.$api.getStorage().then((resolve) =>{
  130. this.userID = resolve.userID
  131. this.getInitCrearOrder(option);
  132. })
  133. },
  134. methods: {
  135. getInitCrearOrder(option){//获取订单商品信息
  136. let params ={userId:this.userID,count:this.productCount,productIds:this.productIds}
  137. createOrderInfo(params).then(response =>{
  138. let resData = response.data
  139. this.isRequest = true
  140. this.goodsData = resData.shopList
  141. this.userMoney = resData.userMoney
  142. }).catch(error =>{
  143. this.$util.msg(error.msg,2000)
  144. })
  145. },
  146. getFreightData(){//获取邮费信息
  147. let params ={
  148. userId:this.userID,
  149. productIds:this.productIds,
  150. totalPrice:this.allPrice,
  151. townId:this.addressData.townID
  152. }
  153. getOrderPostage(params).then(response =>{
  154. this.isFreight = true
  155. this.freightData = response.data
  156. this.hanldFreePostFlag = response.data.freePostFlag
  157. this.hanldFreight = response.data.freight
  158. if(this.hanldFreePostFlag == 1){
  159. this.payAllPrice = this.allPrice + response.data.freight
  160. }else{
  161. this.payAllPrice = this.allPrice
  162. }
  163. })
  164. },
  165. getAddressData(){//获取地址信息
  166. this.$api.getStorage().then((resolve) => {
  167. queryAddressList({pageNum:1,pageSize:1,userID:resolve.userID}).then(response =>{
  168. this.isAddress = true
  169. this.addressData = {}
  170. if(response.data.results != ''){
  171. this.addressID = response.data.results[0].addressID;
  172. this.townID = response.data.results[0].townID;
  173. this.addressData = response.data.results[0];
  174. this.getFreightData()
  175. }else{
  176. this.addressData = this.addressData;
  177. }
  178. })
  179. })
  180. },
  181. handChangeInputGoodsList(data){//对应供应商的留言信息
  182. this.goodsData = data;
  183. },
  184. handleChoiceaInvoiceData(data){//获取发票信息
  185. this.invoiceData = data
  186. },
  187. hanldFreightFn(data){//显示邮费弹窗
  188. switch(data){
  189. case 1:
  190. this.hanldFreight = this.freightData.freight
  191. this.hanldFreePostFlag = data
  192. this.payAllPrice =this.allPrice + this.hanldFreight
  193. this.attributePallPrice()
  194. break
  195. case -1:
  196. this.hanldFreight = 0
  197. this.hanldFreePostFlag = data
  198. this.payAllPrice = this.allPrice
  199. this.attributePallPrice()
  200. break
  201. }
  202. },
  203. checkedBalabce(){//勾选使用余额
  204. if(this.userMoney > 0){
  205. this.ischecked = !this.ischecked
  206. if(this.ischecked){
  207. this.balanceDeductionFlag =1
  208. this.attributePallPrice()
  209. }else{
  210. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  211. this.payAllPrice = this.allPrice+parseInt(this.freightData.freight)
  212. }else{
  213. this.payAllPrice = this.allPrice
  214. }
  215. this.balanceDeductionFlag = 2
  216. }
  217. }else{
  218. return
  219. }
  220. },
  221. attributePallPrice(){//计算价格
  222. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  223. this.attributeHashfreight(this.freightData.freight)
  224. }else{
  225. this.attributeNofreight()
  226. }
  227. },
  228. attributeNofreight(){//计算没有邮费的支付价格
  229. if(this.ischecked){
  230. if(this.userMoney>this.payAllPrice){
  231. this.payAllPrice = 0.00
  232. this.deductMoney = this.allPrice //勾选后使用抵余额
  233. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  234. }else{
  235. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  236. this.deductMoney = this.userMoney //勾选后使用抵余额
  237. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  238. }
  239. }else{
  240. this.payAllPrice = this.allPrice;
  241. this.deductMoney = 0.00;
  242. this.surplusMoney = this.userMoney;
  243. }
  244. },
  245. attributeHashfreight(freight){//计算需要邮费的支付价格
  246. this.payAllPrice = this.allPrice+parseInt(freight)//计算不包邮的价格 总价等于商品价格+邮费
  247. if(this.ischecked){
  248. if(this.userMoney>this.payAllPrice){ //余额大于支付金额
  249. this.payAllPrice =0.00
  250. this.deductMoney = this.allPrice+parseInt(freight) //勾选后使用抵余额
  251. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  252. }else{
  253. this.payAllPrice = this.allPrice+parseInt(freight) - this.userMoney //勾选后的总价
  254. this.deductMoney = this.userMoney //勾选后使用抵余额
  255. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  256. }
  257. }else{
  258. this.payAllPrice = this.allPrice+parseInt(freight)
  259. this.deductMoney = 0.00
  260. this.surplusMoney = this.userMoney
  261. }
  262. },
  263. orderSubmitMit(){//提交订单
  264. if(this.addressID == ''){
  265. this.$util.msg('请先添加收货地址~',2000)
  266. return
  267. }
  268. this.orderInfo = this.goodsData.map(el => {
  269. let productInfo = [];
  270. el.productsList.forEach(item => {
  271. productInfo.push({
  272. productId:item.productID,
  273. productNum:item.productCount,
  274. presentNum:0
  275. })
  276. })
  277. return {shopId:el.shopID,note:el.note?el.note:'',productInfo:productInfo}
  278. })
  279. //订单信息
  280. this.payInfo = {
  281. clauseId:0,//条款(暂时保留)
  282. orderShouldPayFee:this.payAllPrice.toFixed(2),//提交的总价
  283. balancePayFlag:this.balanceDeductionFlag,//余额抵扣的状态
  284. freight:parseInt(this.hanldFreight).toFixed(2),//邮费
  285. freePostFlag:parseInt(this.hanldFreePostFlag)//运费形式
  286. }
  287. let param = {
  288. orderSource:6,
  289. clubUserId:this.userID,
  290. cartType:this.cartType,
  291. addressId:this.addressID,
  292. orderInfo:this.orderInfo,
  293. payInfo:this.payInfo, //订单信息
  294. orderInvoice:this.invoiceData
  295. }
  296. // console.log(param)
  297. this.modalLayer = true;
  298. createOrderSubmit({'params':JSON.stringify(param)}).then(response =>{
  299. if(response.code === 1){
  300. this.submitState ='success'
  301. let data = {orderID:response.data.orderID}
  302. this.$api.navigateTo(`/pages/user/order/success?data=${JSON.stringify({data:data})}`)
  303. }else if(response.code === 2){
  304. this.submitState ='confirm'
  305. this.$api.redirectTo(`/pages/user/order/order-payment?type=${this.submitState}&orderID=${response.data.orderID}`)
  306. }else{
  307. this.$util.msg(response.msg,2000);
  308. }
  309. }).catch(error =>{})
  310. },
  311. handFreightAlertShow(){//显示邮费弹窗
  312. this.isfreightTip = true;
  313. },
  314. hideFreight(){//关闭邮费弹窗
  315. this.isfreightTip = false;
  316. },
  317. },
  318. onShow() {
  319. // this.addressID = ''
  320. let pages = getCurrentPages();
  321. let currPage = pages[pages.length-1];
  322. if(currPage.data.select =='select'){
  323. this.isAddress = true
  324. let SelectData = uni.getStorageSync('selectAddress');
  325. this.addressID = SelectData.addressID;
  326. this.addressData = SelectData
  327. this.getFreightData()
  328. }else{
  329. this.getAddressData()
  330. }
  331. }
  332. }
  333. </script>
  334. <style lang="scss">
  335. page {
  336. height: auto;
  337. background:#F7F7F7;
  338. }
  339. .btn-hover{
  340. background: #FFFFFF;
  341. }
  342. .animation{
  343. /* transition: transform 0.3s ease;*/
  344. transition-property: transform;
  345. transition-duration: 0.3s;
  346. transition-timing-function: ease;
  347. }
  348. .order{
  349. padding-bottom: 134rpx;
  350. }
  351. .invoice-freight{
  352. width: 702rpx;
  353. padding: 0 24rpx;
  354. height: 86rpx;
  355. line-height: 86rpx;
  356. font-size: $font-size-28;
  357. color: $text-color;
  358. background: #FFFFFF;
  359. float: left;
  360. font-weight: bold;
  361. .freight-left{
  362. float: left;
  363. .icon-yunfeishuoming{
  364. height: 100%;
  365. padding: 0 15rpx;
  366. color: $color-system;
  367. font-weight: normal;
  368. }
  369. }
  370. .freight-right{
  371. float: right;
  372. color: #2A81FF;
  373. }
  374. }
  375. .invoice-balance{
  376. width: 702rpx;
  377. height: auto;
  378. padding:0 24rpx;
  379. background: #FFFFFF;
  380. float: left;
  381. margin-top: 24rpx;
  382. margin-bottom: 24rpx;
  383. .balabce-t{
  384. width: 100%;
  385. height: 86rpx;
  386. line-height: 86rpx;
  387. font-size: $font-size-28;
  388. color: $text-color;
  389. float: left;
  390. .balabce-t-le{
  391. float: left;
  392. font-weight: bold;
  393. }
  394. .balabce-t-ri{
  395. float: right;
  396. display: flex;
  397. align-items: center;
  398. .money{
  399. display: flex;
  400. float: left;
  401. }
  402. .checkbox-box{
  403. display: flex;
  404. width: 60rpx;
  405. float: left;
  406. height: 100%;
  407. font-size: $font-size-24;
  408. .checkbox{
  409. width: 40rpx;
  410. text-align: right;
  411. box-sizing: border-box;
  412. text-align: center;
  413. text-decoration: none;
  414. border-radius: 0;
  415. -webkit-tap-highlight-color: transparent;
  416. overflow: hidden;
  417. color: $color-system;
  418. }
  419. }
  420. }
  421. }
  422. .balabce-b{
  423. width: 100%;
  424. float: left;
  425. overflow: hidden;
  426. .balabce-b-text{
  427. width: 100%;
  428. line-height: 58rpx;
  429. font-size: $font-size-24;
  430. color: #FF2A2A;
  431. text-align: right;
  432. float: right;
  433. }
  434. &.balabce-b--hide {
  435. padding: 0 0;
  436. height: 0px;
  437. line-height: 0px;
  438. }
  439. }
  440. }
  441. .footer{
  442. position: fixed;
  443. left: 0;
  444. bottom: 0;
  445. z-index: 995;
  446. display: flex;
  447. align-items: center;
  448. width: 100%;
  449. height: 110rpx;
  450. line-height: 110rpx;
  451. justify-content: space-between;
  452. font-size: $font-size-28;
  453. background-color: #FFFFFF;
  454. z-index: 998;
  455. color: $text-color;
  456. .footer-le{
  457. width:550rpx;
  458. height:100%;
  459. float: left;
  460. }
  461. .footer-count{
  462. float: left;
  463. padding-left: 24rpx;
  464. font-weight: bold;
  465. }
  466. .footer-price{
  467. float: right;
  468. text-align: right;
  469. color: $text-color;
  470. font-weight: bold;
  471. padding-right: 24rpx;
  472. .price{
  473. font-size: $font-size-32;
  474. color: #FF2A2A;
  475. }
  476. }
  477. .footer-submit{
  478. display:flex;
  479. align-items:center;
  480. justify-content: center;
  481. width: 200rpx;
  482. height: 100%;
  483. color: #FFFFFF;
  484. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  485. }
  486. }
  487. </style>