create-order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <view class="container order clearfix">
  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" v-if="isRequest" :invoiceData="invoiceData"></invoice-tent>
  11. <!-- 运费 -->
  12. <freight ref="freight" v-if="isRequest" :freightData="freightData" @showFreightAlert="handFreightAlertShow"></freight>
  13. <freight-alert v-if="isfreightTip" ref="csPhone"></freight-alert>
  14. <!-- 余额抵扣 -->
  15. <view class="invoice-balance">
  16. <view class="balabce-t">
  17. <view class="balabce-t-le">余额抵扣</view>
  18. <view class="balabce-t-ri">
  19. <view class="money">
  20. <text>可用余额:</text>
  21. <text>¥{{userMoney.toFixed(2)}}</text>
  22. </view>
  23. <view class="checkbox-box">
  24. <button class="checkbox iconfont"
  25. hover-class="btn-hover"
  26. v-if="userMoney!=0"
  27. @click.stop="checkedBalabce"
  28. :class="[ischecked ?'icon-gouxuanl':'icon-weigouxuan']"
  29. >
  30. </button>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="balabce-b" :class="{'balabce-b--hide':!ischecked}">
  35. <view class="balabce-b-text animation" :style="{'transform':ischecked?'translateY(0)':'translateY(-50%)','-webkit-transform':ischecked?'translateY(0)':'translateY(-50%)'}">
  36. <text>当前使用:¥{{deductMoney.toFixed(2)}},剩余:¥{{surplusMoney.toFixed(2)}}</text>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 底部 -->
  41. <view class="footer" :style="{paddingBottom :isIphoneX ? '68rpx' : '0rpx'}">
  42. <view class="footer-le">
  43. <view class="footer-count">
  44. <text>共{{allCount}}件商品</text>
  45. </view>
  46. <view class="footer-price">
  47. <text>总价:<text class="price">¥{{payAllPrice.toFixed(2)}}</text></text>
  48. </view>
  49. </view>
  50. <view class="footer-submit" @click.stop="submit">提交订单</view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import choiceAddress from '@/components/module/creatOrder/choiceAddress'
  56. import goodsList from '@/components/module/creatOrder/goodsList'
  57. import invoiceTent from '@/components/module/creatOrder/invoiceTent'
  58. import freight from '@/components/module/creatOrder/freight'
  59. import freightAlert from '@/components/module/modelAlert/freightAlert'
  60. import modalLayer from "@/components/modal-layer"
  61. import { queryAddressList } from "@/api/cart.js"
  62. import { createOrderInfo,createOrderSubmit,getOrderPostage } from "@/api/order.js"
  63. export default {
  64. components:{
  65. choiceAddress,
  66. goodsList,
  67. invoiceTent,
  68. freight,
  69. freightAlert,
  70. modalLayer
  71. },
  72. data() {
  73. return {
  74. modallayer:false,
  75. orderID:0,
  76. productIds:'', //获取上一级页面商品信息
  77. productCount:'', //获取上一级页面商品数量
  78. classifyIDS:'', //获取上一级页面商品分类
  79. userID:'', //用户ID
  80. cartType:'', //购买类型(1购物车提交,2直接购买提交)
  81. submitState:'', //提交状态
  82. balanceDeductionFlag:2, //勾选余额的状态(1使用,2不使用)
  83. allCount:1, //订单提交总数量
  84. payAllPrice:0.00, //订单提交总金额
  85. allPrice:0.00, //订单总金额
  86. surplusMoney:0.00, //显示勾选后的剩余抵扣
  87. userMoney:0.00, //显示可使用余额
  88. deductMoney:0.00, //显示已使用的余额
  89. addressID:'', //地址ID
  90. townID:'', //区ID
  91. isRequest:false, //是否加载完成渲染子组件
  92. isAddress:false, //是否加载完成地址
  93. isfreightTip:false, //控制邮费弹窗
  94. ischecked:false, //是否勾选余额
  95. addressData:{}, //初始化地址信息
  96. goodsData:[], //初始化商品信息
  97. invoiceData:{}, //初始化发票信息
  98. freightData:{}, //邮费数据
  99. orderInfo:[], //提交的商品信息
  100. isIphoneX:this.$store.state.isIphoneX
  101. }
  102. },
  103. onLoad(option){//商品数据
  104. let data = JSON.parse(option.data);
  105. console.log(data)
  106. this.allPrice = data.data.allPrice;
  107. this.allCount = data.data.allCount;
  108. this.payAllPrice = this.allPrice;
  109. // console.log(data)
  110. if(option.type =='prodcut'){
  111. this.cartType = 2
  112. this.productCount = data.data.productCount
  113. this.productIds = data.data.productID
  114. // this.classifyIDS = data.data.classifyID
  115. }else{
  116. this.cartType = 1
  117. this.productCount = data.data.productCount
  118. this.productIds = data.data.productID
  119. // this.classifyIDS = data.data.classifyID
  120. }
  121. this.getInitCrearOrder(option);
  122. // this.getAddressData()
  123. },
  124. methods: {
  125. getInitCrearOrder(option){//获取订单商品信息&&邮费信息&&发票信息
  126. this.$api.getStorage().then((resolve) =>{
  127. this.userID = resolve.userID
  128. let params ={userId:this.userID,count:this.productCount,productIds:this.productIds}
  129. createOrderInfo(params).then(response =>{
  130. let resData = response.data
  131. this.isRequest = true
  132. this.goodsData = resData.shopList
  133. this.userMoney = resData.userMoney
  134. this.freightData = {freePostFlag:resData.freight}
  135. this.invoiceData = resData.invoice
  136. this.goodsData = resData.shopList
  137. }).catch(response =>{
  138. this.$util.msg(response.msg,2000)
  139. })
  140. })
  141. },
  142. getAddressData(){//获取地址信息
  143. this.$api.getStorage().then((resolve) =>{
  144. queryAddressList({pageNum:1,pageSize:1,userID:resolve.userID}).then(response =>{
  145. this.isAddress = true
  146. this.addressData = {}
  147. if(response.data.results != ''){
  148. this.addressID = response.data.results[0].addressID;
  149. this.townID = response.data.results[0].townID;
  150. this.addressData = response.data.results[0];
  151. }else{
  152. this.addressData = this.addressData;
  153. }
  154. })
  155. })
  156. },
  157. handChangeInputGoodsList(data){//对应供应商的留言信息
  158. this.goodsData = data;
  159. // console.log(this.goodsData)
  160. },
  161. submit(){//提交订单
  162. if(this.addressID == ''){
  163. this.$util.msg('请先添加收货地址~',2000)
  164. return
  165. }
  166. this.orderInfo = this.goodsData.map(el => {
  167. let productInfo = [];
  168. el.productsList.forEach(item => {
  169. productInfo.push({
  170. productId:item.productID,
  171. productNum:item.productCount
  172. })
  173. })
  174. if(el.note == null){
  175. el.note = ''
  176. }else{
  177. el.note = el.note
  178. }
  179. return {shopId:el.shopID,note:el.note,productInfo:productInfo}
  180. })
  181. let orderInvoice;
  182. if(this.invoiceData != null){
  183. orderInvoice= Object.assign(this.invoiceData,'',{type:0})
  184. }else{
  185. orderInvoice ={
  186. type:0,
  187. invoiceTitleType:'',
  188. invoiceTitle:'',
  189. corporationTaxNum:'',
  190. registeredAddress:'',
  191. registeredPhone:'',
  192. bankAccountNo:'',
  193. openBank:'',
  194. }
  195. }
  196. let param = {
  197. orderSource:6,
  198. userId:this.userID,
  199. cartType:this.cartType,
  200. addressId:this.addressID,
  201. orderInfo:this.orderInfo,
  202. balanceDeductionFlag:this.balanceDeductionFlag,
  203. orderShouldPayFee:this.payAllPrice,
  204. orderInvoice:orderInvoice
  205. }
  206. this.modalLayer = true;
  207. // console.log(JSON.stringify(param))
  208. createOrderSubmit({'params':JSON.stringify(param)}).then(response =>{
  209. if(response.code === 1){
  210. this.submitState ='success'
  211. let data = {orderID:response.data.orderID}
  212. this.$api.navigateTo(`/pages/user/order/order-cashier?type=${this.submitState}&data=${JSON.stringify({data:data})}`)
  213. }else if(response.code === 2){
  214. this.submitState ='nosuccess'
  215. let data = {
  216. orderID:response.data.orderID,
  217. orderNo:response.data.orderNo,
  218. orderMark:response.data.orderMark,
  219. payableAmount:response.data.payableAmount
  220. }
  221. this.$api.navigateTo(`/pages/user/order/order-cashier?type=${this.submitState}&data=${JSON.stringify({data:data})}`)
  222. }else{
  223. this.$util.msg(response.msg,2000);
  224. }
  225. }).catch(response =>{
  226. })
  227. },
  228. getPostage(){
  229. this.$api.getStorage().then((resolve) =>{
  230. let params ={
  231. userId:resolve.userID,
  232. productIds:this.productIds,
  233. totalPrice:this.allPrice,
  234. townID:this.addressData.townID
  235. }
  236. getOrderPostage(params).then(response =>{
  237. console.log(response)
  238. })
  239. })
  240. },
  241. handFreightAlertShow(){//显示邮费弹窗
  242. this.isfreightTip = true;
  243. },
  244. hideFreight(){//关闭邮费弹窗
  245. this.isfreightTip = false;
  246. },
  247. checkedBalabce(){//勾选使用余额
  248. if(this.userMoney == 0){
  249. return
  250. }else{
  251. this.ischecked = !this.ischecked
  252. if(this.ischecked){
  253. this.balanceDeductionFlag =1
  254. if(this.userMoney>this.payAllPrice){
  255. this.payAllPrice =0.00
  256. this.deductMoney = this.allPrice //勾选后使用抵余额
  257. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  258. }else{
  259. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  260. this.deductMoney = this.userMoney //勾选后使用抵余额
  261. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  262. }
  263. }else{
  264. this.payAllPrice = this.allPrice
  265. this.balanceDeductionFlag = 2
  266. }
  267. }
  268. }
  269. },
  270. onShow() {
  271. // this.addressID = ''
  272. let pages = getCurrentPages();
  273. let currPage = pages[pages.length-1];
  274. if(currPage.data.select =='select'){
  275. this.isAddress = true
  276. let SelectData = uni.getStorageSync('selectAddress');
  277. this.addressID = SelectData.addressID;
  278. this.addressData = SelectData
  279. this.getPostage()
  280. }else{
  281. this.getAddressData()
  282. }
  283. }
  284. }
  285. </script>
  286. <style lang="scss">
  287. page {
  288. height: auto;
  289. background:#F7F7F7;
  290. }
  291. .btn-hover{
  292. background: #FFFFFF;
  293. }
  294. .animation{
  295. /* transition: transform 0.3s ease;*/
  296. transition-property: transform;
  297. transition-duration: 0.3s;
  298. transition-timing-function: ease;
  299. }
  300. .order{
  301. padding-bottom: 134rpx;
  302. }
  303. .invoice-freight{
  304. width: 702rpx;
  305. padding: 0 24rpx;
  306. height: 86rpx;
  307. line-height: 86rpx;
  308. font-size: $font-size-28;
  309. color: $text-color;
  310. background: #FFFFFF;
  311. float: left;
  312. font-weight: bold;
  313. .freight-left{
  314. float: left;
  315. .icon-yunfeishuoming{
  316. height: 100%;
  317. padding: 0 15rpx;
  318. color: $color-system;
  319. font-weight: normal;
  320. }
  321. }
  322. .freight-right{
  323. float: right;
  324. color: #2A81FF;
  325. }
  326. }
  327. .invoice-balance{
  328. width: 702rpx;
  329. height: auto;
  330. padding:0 24rpx;
  331. background: #FFFFFF;
  332. float: left;
  333. margin-top: 24rpx;
  334. margin-bottom: 24rpx;
  335. .balabce-t{
  336. width: 100%;
  337. height: 86rpx;
  338. line-height: 86rpx;
  339. font-size: $font-size-28;
  340. color: $text-color;
  341. float: left;
  342. .balabce-t-le{
  343. float: left;
  344. font-weight: bold;
  345. }
  346. .balabce-t-ri{
  347. float: right;
  348. display: flex;
  349. align-items: center;
  350. .money{
  351. display: flex;
  352. float: left;
  353. }
  354. .checkbox-box{
  355. display: flex;
  356. width: 60rpx;
  357. float: left;
  358. height: 100%;
  359. font-size: $font-size-24;
  360. .checkbox{
  361. width: 40rpx;
  362. text-align: right;
  363. box-sizing: border-box;
  364. text-align: center;
  365. text-decoration: none;
  366. border-radius: 0;
  367. -webkit-tap-highlight-color: transparent;
  368. overflow: hidden;
  369. color: $color-system;
  370. }
  371. }
  372. }
  373. }
  374. .balabce-b{
  375. width: 100%;
  376. float: left;
  377. overflow: hidden;
  378. .balabce-b-text{
  379. width: 100%;
  380. line-height: 58rpx;
  381. font-size: $font-size-24;
  382. color: #FF2A2A;
  383. text-align: right;
  384. float: right;
  385. }
  386. &.balabce-b--hide {
  387. padding: 0 0;
  388. height: 0px;
  389. line-height: 0px;
  390. }
  391. }
  392. }
  393. .footer{
  394. position: fixed;
  395. left: 0;
  396. bottom: 0;
  397. z-index: 995;
  398. display: flex;
  399. align-items: center;
  400. width: 100%;
  401. height: 110rpx;
  402. line-height: 110rpx;
  403. justify-content: space-between;
  404. font-size: $font-size-28;
  405. background-color: #FFFFFF;
  406. z-index: 998;
  407. color: $text-color;
  408. .footer-le{
  409. width:550rpx;
  410. height:100%;
  411. float: left;
  412. }
  413. .footer-count{
  414. float: left;
  415. padding-left: 24rpx;
  416. font-weight: bold;
  417. }
  418. .footer-price{
  419. float: right;
  420. text-align: right;
  421. color: $text-color;
  422. font-weight: bold;
  423. padding-right: 24rpx;
  424. .price{
  425. font-size: $font-size-32;
  426. color: #FF2A2A;
  427. }
  428. }
  429. .footer-submit{
  430. display:flex;
  431. align-items:center;
  432. justify-content: center;
  433. width: 200rpx;
  434. height: 100%;
  435. color: #FFFFFF;
  436. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  437. }
  438. }
  439. </style>