payment.vue 21 KB

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