payment.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <div class="min-h-[500px]" v-loading="createLoading">
  3. <div class="main-container pt-[30px]" v-if="Object.keys(orderData).length">
  4. <div v-if="orderData.basic.has_goods_types.includes('real')">
  5. <div class="bg-[#fff] mb-[20px] px-[30px] pt-[30px] pb-[20px]">
  6. <div class="text-[16px] text-[#333] mb-[20px]">{{ t('deliveryAddress') }}</div>
  7. <div class="flex flex-wrap h-[106px] justify-between overflow-hidden" id="address-list">
  8. <div class="w-[560px] h-[90px] leading-[90px] text-[#333] text-[14px] border-[1px] border-solid border-[#ccc] text-center cursor-pointer" @click="addAddressFn">
  9. <span class="text-[#666]">+</span>
  10. <span>{{ t('addDeliveryAddress') }}</span>
  11. </div>
  12. <template v-for="(item, index) in addressList">
  13. <div class="w-[560px] h-[90px] border-[1px] border-solid border-[#ccc] p-[20px] mb-[20px] overflow-hidden relative cursor-pointer" :class="{'!border-[var(--el-color-primary)]': orderData.delivery.take_address.id == item.id}" @click="selectAddressFn(item)">
  14. <div class="flex items-center font-500 mb-[10px] text-[14px] text-[#333]">
  15. <span class="truncate max-w-[200px]">{{item.name}}</span>
  16. <span>{{item.mobile}}</span>
  17. <span class="text-[12px] text-[#fff] bg-[var(--el-color-primary)] text-center px-[4px] py-[2px] rounded-[2px] ml-[6px]" v-if="item.is_default == 1">{{ t('default') }}</span>
  18. </div>
  19. <div class="text-[14px] text-[#666] font-400 truncate leading-[18px] oppoSans-R">{{item.full_address}}</div>
  20. <div class="iconfont icon-xuanzhong4 !text-[27px] text-[var(--el-color-primary)] absolute bottom-[-2px] right-[-2px]" v-if="orderData.delivery.take_address.id == item.id"></div>
  21. </div>
  22. </template>
  23. </div>
  24. <div v-if="addressList.length">
  25. <div class="pt-[14px] text-center text-[#666] cursor-pointer text-[14px]" @click="showMoreAddress" v-if="activeAddress">{{ t('allAddress') }}
  26. <span class="iconfont icon-xiajiantou !text-[12px] ml-[4px]"></span>
  27. </div>
  28. <div class="pt-[14px] text-center text-[#666] cursor-pointer text-[14px]" @click="hiddenMoreAddress" v-else>{{ t('packUp') }}
  29. <span class="iconfont icon-xiangshangjiantou !text-[12px] ml-[4px]"></span>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="">
  35. <div v-for="(item, key, index) in orderData.order_list" :key="index">
  36. <div class="bg-[#fff] px-[30px] pt-[30px] pb-[20px] mb-[20px]">
  37. <div class="flex items-center mb-[30px]">
  38. <span class="iconfont icon-Vector-25 text-[#999] mr-[6px]"></span>
  39. <span class="text-[14px] text-[#333]">{{item.site_info.site_name}}</span>
  40. </div>
  41. <div>
  42. <template v-for="(subItem, subKey, subIndex) in item.goods_data" :key="subIndex">
  43. <div class="mb-[30px] flex items-center justify-between" >
  44. <div class="flex">
  45. <div class="w-[100px] h-[100px]">
  46. <el-image class="w-[100px] h-[100px]" :src="img(subItem.sku_image)" fit="cover">
  47. <template #error>
  48. <img src="@/assets/images/goods_default.png" class="w-[100px] h-[100px]">
  49. </template>
  50. </el-image>
  51. </div>
  52. <div class="ml-[20px] flex flex-col justify-center text-[14px] ">
  53. <div class="text-[#333] font-500 w-[580px] truncate mb-[14px]"> {{ subItem.goods.goods_name }}</div>
  54. <div class="text-[#919191] oppoSans-R" v-if="subItem.sku_name">规格:{{ subItem.sku_name }}</div>
  55. </div>
  56. </div>
  57. <div class="flex justify-center items-center">
  58. <div class="w-[160px] text-[14px] text-[#333] oppoSans-R">¥{{subItem.price}}</div>
  59. <div class="w-[100px] text-[14px] text-[#333] text-right oppoSans-R">x{{ subItem.num }}</div>
  60. <div class="w-[160px] text-[var(--el-price)] text-right">
  61. <span class="text-[12px] price-font">¥</span>
  62. <span class="font-600 text-[18px] price-font">{{ parseFloat(Number(subItem.price) * Number(subItem.num)).toFixed(2) }}</span>
  63. </div>
  64. </div>
  65. </div>
  66. </template>
  67. <div class="h-[1px] border-t-[1px] border-dashed border-[#dcdfe6] my-[24px]"></div>
  68. </div>
  69. <div class="mb-[30px] flex justify-between items-center" v-if="orderData.basic.has_goods_types[0] != 'virtual'">
  70. <div class="text-[16px] text-[#666]">{{ t('deliveryMoney') }}</div>
  71. <div class="text-[16px] text-[#333] price-font">¥{{parseFloat(item.basic.delivery_money).toFixed(2)}}</div>
  72. </div>
  73. <!-- 优惠劵 -->
  74. <div class="mb-[30px] flex justify-between items-center">
  75. <div class="text-[16px] text-[#666]">店铺优惠</div>
  76. <div>
  77. <div class="text-[16px] text-[333] cursor-pointer" v-if="couponData[key] && couponData[key].couponList.length" @click="couponRef.open(createData.body[key])">
  78. <span class="price-font">-¥{{parseFloat(item.basic.discount_money).toFixed(2)}}</span>
  79. <span class="iconfont icon-xiaV6xx !text-[20px]"></span>
  80. </div>
  81. <div v-else class="text-[#666]">暂无可使用优惠</div>
  82. </div>
  83. </div>
  84. <div class="mb-[30px] flex items-center" v-if="item.config && item.config.invoice &&item.config.invoice.is_invoice == 1">
  85. <div class="text-[16px] text-[#666]">{{ t('invoiceInfo') }}</div>
  86. <div class="ml-[30px] flex-1 flex items-center justify-between">
  87. <div class="flex items-center">
  88. <div class="mr-[15px] cursor-pointer relative border-[1px] border-solid border-[#d3d3d3] flex box-border px-[50px] leading-[32px] text-[14px]" :class="{'!border-primary text-primary': !createData.body[key].invoice }" @click="notInvoiceFn(item,key)">
  89. <div>{{ t('noInvoice') }}</div>
  90. <div class="iconfont icon-xuanzhong4 !text-[22px] text-primary absolute bottom-[-3px] right-[-1px]" v-if="!createData.body[key].invoice"></div>
  91. </div>
  92. <div class="mr-[15px] cursor-pointer relative border-[1px] border-solid border-[#d3d3d3] flex box-border px-[50px] leading-[32px] text-[14px]" :class="{'!border-primary text-primary': createData.body[key].invoice && createData.body[key].invoice.header_name }" @click="invoiceFn(item)">
  93. <div>{{ t('electronicInvoice') }}</div>
  94. <div class="iconfont icon-xuanzhong4 !text-[22px] text-primary absolute bottom-[-3px] right-[-1px]" v-if="createData.body[key].invoice && createData.body[key].invoice.header_name"></div>
  95. </div>
  96. </div>
  97. <div class="ml-auto flex items-center text-primary" v-if="createData.body[key].invoice">
  98. <div class="ml-[20px]">{{ createData.body[key].invoice ? createData.body[key].invoice.header_name : '' }}</div>
  99. <div class="ml-[20px]">{{ createData.body[key].invoice && createData.body[key].invoice.header_type == 1 ? t('person') : t('company') }}</div>
  100. <div class="ml-[20px] cursor-pointer" @click="editInvoice(createData.body[key].invoice)">{{ t('update') }}</div>
  101. </div>
  102. </div>
  103. </div>
  104. <div class="mb-[30px] flex">
  105. <div class="text-[16px] text-[#666]">{{ t('remark') }}</div>
  106. <div class="ml-[30px] flex items-center">
  107. <el-input v-model="createData.body[key].member_remark" style="width: 1040px;height: 120px;" type="textarea" :placeholder="t('remarkPlaceholder')" :input-style="{height: '120px'}" resize="none" maxlength="50" />
  108. </div>
  109. </div>
  110. <div class="flex items-center justify-end text-[14px]">
  111. <span>共{{item.basic.total_num}}{{ t('unit') }}</span>
  112. <div class="ml-[10px]">
  113. <span>{{ t('subTotal') }}</span>
  114. <span class="price-font">¥{{ parseFloat(item.basic.order_money + item.basic.mall_discount_money).toFixed(2) }}</span>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. <!--平台优惠劵 -->
  121. <div class="bg-[#fff] px-[30px] py-[30px] mb-[20px]" v-if="platformCouponData && platformCouponData.length">
  122. <div class="flex items-center justify-between">
  123. <div class="text-[16px] text-[#666] w-[64px] flex-shrink-0">{{ t('platformCoupon') }}</div>
  124. <div class="text-[16px] text-[333] cursor-pointer" @click="platformCouponRef.open(createData.mall_discount.platform_coupon_id)">
  125. <div v-if="orderData.discount && orderData.discount.platform_coupon">
  126. <span class="price-font"> -¥{{ orderData.discount.platform_coupon.money }}</span>
  127. <span class="iconfont icon-xiaV6xx !text-[20px]"></span>
  128. </div>
  129. <div class="text-[26rpx] text-gray-subtitle" v-else>
  130. <span>请选择平台优惠券</span>
  131. <span class="iconfont icon-xiaV6xx !text-[20px]"></span>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. <div class="bg-[#fff] px-[30px] pt-[30px] pb-[20px]">
  137. <div class="bg-[#f7f7f7] p-[20px]">
  138. <div class="flex justify-between items-center mb-[15px] text-[14px]">
  139. <div class="text-[#666]">{{ t('goodsMoney') }}</div>
  140. <div class="text-[#333] price-font">¥{{parseFloat(orderData.basic.goods_money).toFixed(2) }}</div>
  141. </div>
  142. <div class="flex justify-between items-center mb-[15px] text-[14px]" v-if="orderData.basic.shop_discount_money">
  143. <div class="text-[#666]">{{ t('discountMoney') }}</div>
  144. <div class="text-[#333] price-font">-¥{{parseFloat(orderData.basic.shop_discount_money).toFixed(2) }}</div>
  145. </div>
  146. <div class="flex justify-between items-center mb-[15px] text-[14px]" v-if="orderData.basic.mall_discount_money">
  147. <div class="text-[#666]">{{ t('mallDiscountMoney') }}</div>
  148. <div class="text-[#333] price-font">-¥{{parseFloat(orderData.basic.mall_discount_money).toFixed(2) }}</div>
  149. </div>
  150. <div class="flex justify-between items-center mb-[15px] text-[14px]" v-if="orderData.basic.delivery_money">
  151. <div class="text-[#666]">{{ t('deliveryMoney') }}</div>
  152. <div class="text-[#333] price-font">+¥{{ parseFloat(orderData.basic.delivery_money).toFixed(2) }}</div>
  153. </div>
  154. <div class="flex justify-between items-center">
  155. <div class="text-[14px] text-[#666]">{{ t('orderMoney') }}</div>
  156. <div class="text-[var(--el-price)] ">
  157. <span class="text-[14px] price-font">¥</span>
  158. <span class="font-600 text-[22px] price-font">{{ parseFloat(orderData.basic.order_money).toFixed(2) }}</span>
  159. </div>
  160. </div>
  161. </div>
  162. <div class="mt-[30px] flex justify-end items-center">
  163. <el-button class="!w-[120px] !h-[44px] !text-[16px] !bg-primary rounded-[4px] !text-white text-center leading-[44px] !border-none" :loading="createLoading" @click="create">{{ t('submitOrder') }}</el-button>
  164. </div>
  165. </div>
  166. </div>
  167. <!-- 地址 -->
  168. <add-address ref="addAddressRef" @complete="getAddressListFn" @select="handleSelect" />
  169. <!-- 发票 -->
  170. <invoice ref="invoiceRef" @confirm="confirmInvoice" @cancel="cancelInvoice" />
  171. <!-- 店铺优惠劵 -->
  172. <select-coupon :order-key="createData.body" ref="couponRef" @confirm="confirmSelectCoupon" v-if="storeCoupon" />
  173. <!-- 平台优惠劵 -->
  174. <platform-coupon :order-key="createData.body" ref="platformCouponRef" @confirm="confirmPlatformCoupon"/>
  175. </div>
  176. </template>
  177. <script setup lang="ts">
  178. import { ref, reactive,computed } from 'vue'
  179. import { useRouter, useRoute } from 'vue-router'
  180. import storage from '@/utils/storage'
  181. import { getAddressList } from '@/addon/mall/api/address'
  182. import { orderCreateCalculate, orderCoupon, orderCreate, ordePlatformCoupon } from '@/addon/mall/api/order'
  183. import AddAddress from '@/addon/mall/pages/order/components/edit-address.vue'
  184. import invoice from '@/addon/mall/pages/order/components/invoice.vue'
  185. import selectCoupon from '@/addon/mall/pages/order/components/select-coupon.vue'
  186. import platformCoupon from '@/addon/mall/pages/order/components/platform-coupon.vue'
  187. import useCartStore from '@/addon/mall/stores/cart'
  188. const router = useRouter()
  189. const createData = ref({
  190. body:{},
  191. order_key:'',
  192. delivery:{
  193. take_address_id:''
  194. },
  195. mall_discount: {
  196. platform_coupon_id:''
  197. }
  198. })
  199. const createLoading = ref(false)
  200. const couponRef = ref()
  201. const platformCouponRef = ref()
  202. const orderData = ref({})
  203. storage.get('orderCreateData') && Object.assign(createData.value, storage.get('orderCreateData'))
  204. // 获取全部地址
  205. const addressList = ref([])
  206. const getAddressListFn = async () =>{
  207. addressList.value = await( await getAddressList({})).data
  208. }
  209. getAddressListFn()
  210. /**
  211. * 订单计算
  212. */
  213. // 定义一个变量请求店铺优惠劵
  214. let storeCoupon = ref(false)
  215. const calculate = (callback: any = null) => {
  216. createLoading.value = true
  217. orderCreateCalculate(createData.value).then((res) => {
  218. orderData.value = res.data
  219. createData.value.order_key = res.data.order_key
  220. Object.values(orderData.value.order_list).forEach(item =>{
  221. if(createData.value.body[item.site_id] != undefined){
  222. createData.value.body[item.site_id].order_key = item.order_key
  223. createData.value.body[item.site_id].member_remark = ''
  224. createData.value.body[item.site_id].site_id= item.site_id
  225. }
  226. })
  227. storeCoupon.value = true
  228. if(addressList.value.length){
  229. const data = addressList.value.filter(item =>{
  230. return item.id == orderData.value.delivery.take_address.id
  231. })
  232. const curIndex = addressList.value.findIndex(item =>{
  233. return item.id == orderData.value.delivery.take_address.id
  234. })
  235. if(data.length && curIndex != -1){
  236. addressList.value.splice(curIndex,1)
  237. addressList.value.unshift(data[0])
  238. }
  239. }
  240. callback && callback()
  241. createLoading.value = false
  242. }).catch(()=>{
  243. createLoading.value = false
  244. })
  245. }
  246. calculate()
  247. // 选择优惠劵
  248. const couponData = computed(() => {
  249. return couponRef.value?.couponData || {}
  250. })
  251. const confirmSelectCoupon = async () =>{
  252. for(let i in couponData.value){
  253. if(couponData.value[i].coupon){
  254. createData.value.body[i].discount = {}
  255. createData.value.body[i].discount.coupon_id = couponData.value[i].coupon.id
  256. }else{
  257. createData.value.body[i].discount = {}
  258. createData.value.body[i].discount.coupon_id = ''
  259. }
  260. }
  261. createData.value.mall_discount.platform_coupon_id = 0
  262. await calculate((data:any) =>{
  263. // 平台优惠劵
  264. platformCouponRef.value?.ordePlatformCouponFn()
  265. })
  266. }
  267. // 选择平台优惠劵
  268. const platformCouponData = computed(() => {
  269. return platformCouponRef.value?.couponList || []
  270. })
  271. const confirmPlatformCoupon = (data:any) =>{
  272. createData.value.mall_discount.platform_coupon_id = data ? data.id : 0
  273. calculate()
  274. }
  275. // 新增地址后选中新增地址
  276. const handleSelect = (data) =>{
  277. selectAddressFn(data)
  278. }
  279. // 选择地址
  280. const selectAddressFn = (data)=>{
  281. createData.value.delivery.take_address_id = data.id
  282. createData.value.order_key = ''
  283. for(let i in createData.value.body){
  284. createData.value.body[i].order_key = ''
  285. }
  286. calculate()
  287. }
  288. // 添加地址
  289. const addAddressRef = ref(null)
  290. const addAddressFn = ()=>{
  291. addAddressRef.value.setFormData()
  292. addAddressRef.value.dialogAddressVisible = true
  293. }
  294. // 展示更多地址
  295. const activeAddress = ref(true)
  296. const showMoreAddress = () =>{
  297. nextTick(()=>{
  298. activeAddress.value = !activeAddress.value
  299. const addressListDom = document.querySelector('#address-list')
  300. addressListDom.style.height = 'auto'
  301. })
  302. }
  303. // 隐藏更多地址
  304. const hiddenMoreAddress = () =>{
  305. nextTick(()=>{
  306. activeAddress.value = !activeAddress.value
  307. const addressListDom = document.querySelector('#address-list')
  308. addressListDom.style.height = '106px'
  309. })
  310. }
  311. /**
  312. * 校验选择地址
  313. */
  314. const verify = () => {
  315. if (!Object.values(orderData.value.delivery.take_address).length && orderData.value.basic.has_goods_types[0] != 'virtual') {
  316. ElMessage.error('请选择收货地址')
  317. return false
  318. }
  319. return true
  320. }
  321. /**
  322. * 订单创建
  323. */
  324. const create = () => {
  325. if (!verify() || createLoading.value) return
  326. createLoading.value = true
  327. orderCreate(createData.value)
  328. .then(({ data }) => {
  329. if (orderData.value.basic.order_money == 0) {
  330. router.push({ path: '/order/list' })
  331. } else {
  332. // 购物车数量
  333. const cartStore = useCartStore();
  334. cartStore.getList()
  335. router.replace({ path: '/pay/pay', query: { trade_type: data.trade_type, trade_id: data.trade_id } })
  336. }
  337. }).catch(() => {
  338. createLoading.value = false
  339. })
  340. }
  341. // 填写发票
  342. const invoiceRef = ref(null)
  343. // 开具发票
  344. const invoiceFn = (data) =>{
  345. invoiceRef.value.setFormData(data)
  346. invoiceRef.value.dialogInvoiceVisible = true
  347. }
  348. // 不开具发票
  349. const notInvoiceFn = (data,key) =>{
  350. delete createData.value.body[key].invoice
  351. }
  352. // 修改发票
  353. const editInvoice = (data) =>{
  354. invoiceRef.value.open(data)
  355. invoiceRef.value.dialogInvoiceVisible = true
  356. }
  357. const confirmInvoice = (invoice) => {
  358. createData.value.body[invoice.site_id].invoice = {}
  359. Object.assign(createData.value.body[invoice.site_id].invoice, invoice.invoice)
  360. }
  361. const cancelInvoice = (site_id) =>{
  362. if(!createData.value.body[site_id].invoice){
  363. delete createData.value.body[site_id].invoice
  364. }
  365. }
  366. </script>
  367. <style lang="scss" scoped>
  368. /* 多行超出隐藏 */
  369. .multi-hidden {
  370. word-break: break-all;
  371. text-overflow: ellipsis;
  372. overflow: hidden;
  373. display: -webkit-box;
  374. -webkit-line-clamp: 4;
  375. -webkit-box-orient: vertical;
  376. }
  377. .line2-hidden {
  378. word-break: break-all;
  379. text-overflow: ellipsis;
  380. overflow: hidden;
  381. display: -webkit-box;
  382. -webkit-line-clamp: 2;
  383. -webkit-box-orient: vertical;
  384. }
  385. :deep(.coupon){
  386. background-color:#f5f5f5!important;
  387. }
  388. :deep(.coupon .el-dialog__header){
  389. padding: 30px 0 36px!important;
  390. }
  391. :deep(.coupon .el-dialog__body){
  392. padding: 0 25px 30px!important;
  393. max-height: 70vh!important;
  394. overflow-y: auto;
  395. }
  396. :deep(.coupon .el-dialog__body::-webkit-scrollbar){
  397. display: none;
  398. }
  399. </style>