index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <!-- 搜索 -->
  3. <ContentWrap>
  4. <el-form
  5. ref="queryFormRef"
  6. :inline="true"
  7. :model="queryParams"
  8. class="-mb-15px"
  9. label-width="68px"
  10. >
  11. <el-form-item label="订单状态" prop="status">
  12. <el-select v-model="queryParams.status" class="!w-280px" clearable placeholder="全部">
  13. <el-option
  14. v-for="dict in getIntDictOptions(DICT_TYPE.TRADE_ORDER_STATUS)"
  15. :key="dict.value"
  16. :label="dict.label"
  17. :value="dict.value"
  18. />
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="支付方式" prop="payChannelCode">
  22. <el-select
  23. v-model="queryParams.payChannelCode"
  24. class="!w-280px"
  25. clearable
  26. placeholder="全部"
  27. >
  28. <el-option
  29. v-for="dict in getStrDictOptions(DICT_TYPE.PAY_CHANNEL_CODE)"
  30. :key="dict.value"
  31. :label="dict.label"
  32. :value="dict.value"
  33. />
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item label="创建时间" prop="createTime">
  37. <el-date-picker
  38. v-model="queryParams.createTime"
  39. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  40. class="!w-280px"
  41. end-placeholder="自定义时间"
  42. start-placeholder="自定义时间"
  43. type="daterange"
  44. value-format="YYYY-MM-DD HH:mm:ss"
  45. />
  46. </el-form-item>
  47. <el-form-item label="订单来源" prop="terminal">
  48. <el-select v-model="queryParams.terminal" class="!w-280px" clearable placeholder="全部">
  49. <el-option
  50. v-for="dict in getIntDictOptions(DICT_TYPE.TERMINAL)"
  51. :key="dict.value"
  52. :label="dict.label"
  53. :value="dict.value"
  54. />
  55. </el-select>
  56. </el-form-item>
  57. <el-form-item label="订单类型" prop="type">
  58. <el-select v-model="queryParams.type" class="!w-280px" clearable placeholder="全部">
  59. <el-option
  60. v-for="dict in getIntDictOptions(DICT_TYPE.TRADE_ORDER_TYPE)"
  61. :key="dict.value"
  62. :label="dict.label"
  63. :value="dict.value"
  64. />
  65. </el-select>
  66. </el-form-item>
  67. <!-- TODO @puhui999:要不加个 deliveryType 筛选;配送方式;然后如果选了快递,就有【快递公司】筛选;如果选了自提,就有【自提门店】;然后把他们这 3 个,坐在一个 el-form-item 里;
  68. 目的是;有的时候,会筛选门店,然后做核销;这个时候,就需要筛选自提门店;
  69. -->
  70. <el-form-item label="快递公司" prop="type">
  71. <el-select v-model="queryParams.logisticsId" class="!w-280px" clearable placeholder="全部">
  72. <el-option
  73. v-for="item in deliveryExpressList"
  74. :key="item.id"
  75. :label="item.name"
  76. :value="item.id"
  77. />
  78. </el-select>
  79. </el-form-item>
  80. <el-form-item label="自提门店" prop="type">
  81. <el-select
  82. v-model="queryParams.pickUpStoreId"
  83. class="!w-280px"
  84. clearable
  85. multiple
  86. placeholder="全部"
  87. >
  88. <el-option
  89. v-for="item in pickUpStoreList"
  90. :key="item.id"
  91. :label="item.name"
  92. :value="item.id"
  93. />
  94. </el-select>
  95. </el-form-item>
  96. <!-- TODO 聚合搜索等售后结束后实现-->
  97. <el-form-item label="聚合搜索">
  98. <el-input
  99. v-show="true"
  100. v-model="queryType.v"
  101. class="!w-280px"
  102. clearable
  103. placeholder="请输入"
  104. >
  105. <template #prepend>
  106. <el-select v-model="queryType.k" class="!w-110px" clearable placeholder="全部">
  107. <el-option
  108. v-for="dict in searchList"
  109. :key="dict.value"
  110. :label="dict.label"
  111. :value="dict.value"
  112. />
  113. </el-select>
  114. </template>
  115. </el-input>
  116. </el-form-item>
  117. <el-form-item>
  118. <el-button @click="handleQuery">
  119. <Icon class="mr-5px" icon="ep:search" />
  120. 搜索
  121. </el-button>
  122. <el-button @click="resetQuery">
  123. <Icon class="mr-5px" icon="ep:refresh" />
  124. 重置
  125. </el-button>
  126. </el-form-item>
  127. </el-form>
  128. </ContentWrap>
  129. <!-- 列表 -->
  130. <ContentWrap>
  131. <el-table v-loading="loading" :data="list">
  132. <el-table-column class-name="order-table-col">
  133. <template #header>
  134. <!-- TODO @phui999:小屏幕下,会有偏移,后续看看 -->
  135. <div class="flex items-center" style="width: 100%">
  136. <div class="ml-100px mr-200px">商品信息</div>
  137. <div class="mr-60px">单价(元)/数量</div>
  138. <div class="mr-60px">售后状态</div>
  139. <div class="mr-60px">实付金额(元)</div>
  140. <div class="mr-60px">买家/收货人</div>
  141. <div class="mr-60px">配送方式</div>
  142. <div class="mr-60px">订单状态</div>
  143. <div class="mr-60px">操作</div>
  144. </div>
  145. </template>
  146. <template #default="scope">
  147. <el-table
  148. :data="scope.row.items"
  149. :header-cell-style="headerStyle"
  150. :span-method="spanMethod"
  151. border
  152. style="width: 100%"
  153. >
  154. <el-table-column min-width="300" prop="spuName">
  155. <template #header>
  156. <div
  157. class="flex items-center"
  158. style="height: 35px; background-color: #f7f7f7; width: 100%"
  159. >
  160. <span class="mr-20px">订单号:{{ scope.row.no }} </span>
  161. <span class="mr-20px">下单时间:{{ formatDate(scope.row.createTime) }}</span>
  162. <span>订单来源:</span>
  163. <dict-tag
  164. :type="DICT_TYPE.TERMINAL"
  165. :value="scope.row.terminal"
  166. class="mr-20px"
  167. />
  168. <span>支付方式:</span>
  169. <dict-tag
  170. v-if="scope.row.payChannelCode"
  171. :type="DICT_TYPE.PAY_CHANNEL_CODE"
  172. :value="scope.row.payChannelCode"
  173. class="mr-20px"
  174. />
  175. <v-else class="mr-20px" v-else>未支付</v-else>
  176. <span class="mr-20px" v-if="scope.row.payTime">
  177. 支付时间:{{ formatDate(scope.row.payTime) }}
  178. </span>
  179. <span>订单类型:</span>
  180. <dict-tag :type="DICT_TYPE.TRADE_ORDER_TYPE" :value="scope.row.type" />
  181. </div>
  182. </template>
  183. <template #default="{ row }">
  184. <div class="flex items-center">
  185. <el-image
  186. :src="row.picUrl"
  187. class="w-30px h-30px mr-10px"
  188. @click="imagePreview(row.picUrl)"
  189. />
  190. <span class="mr-10px">{{ row.spuName }}</span>
  191. <el-tag
  192. v-for="property in row.properties"
  193. :key="property.propertyId"
  194. class="mr-10px"
  195. >
  196. {{ property.propertyName }}: {{ property.valueName }}
  197. </el-tag>
  198. </div>
  199. </template>
  200. </el-table-column>
  201. <el-table-column label="商品原价*数量" prop="price" width="150">
  202. <template #default="{ row }">
  203. {{ floatToFixed2(row.price) }} 元 / {{ row.count }}
  204. </template>
  205. </el-table-column>
  206. <el-table-column label="售后状态" prop="afterSaleStatus" width="120">
  207. <template #default="{ row }">
  208. <dict-tag
  209. :type="DICT_TYPE.TRADE_ORDER_ITEM_AFTER_SALE_STATUS"
  210. :value="row.afterSaleStatus"
  211. />
  212. </template>
  213. </el-table-column>
  214. <el-table-column align="center" label="实际支付" min-width="120" prop="payPrice">
  215. <template #default>
  216. {{ floatToFixed2(scope.row.payPrice) + '元' }}
  217. </template>
  218. </el-table-column>
  219. <el-table-column label="买家/收货人" min-width="160">
  220. <template #default>
  221. <!-- 快递发货 -->
  222. <div v-if="scope.row.deliveryType === 1" class="flex flex-col">
  223. <span>买家:{{ scope.row.user.nickname }}</span>
  224. <span>
  225. 收货人:{{ scope.row.receiverName }} {{ scope.row.receiverMobile }}
  226. {{ scope.row.receiverAreaName }} {{ scope.row.receiverDetailAddress }}
  227. </span>
  228. </div>
  229. <!-- 自提 -->
  230. <div v-if="scope.row.deliveryType === 2" class="flex flex-col">
  231. <span>
  232. 门店名称:
  233. {{ pickUpStoreList.find((p) => p.id === scope.row.pickUpStoreId)?.name }}
  234. </span>
  235. <span>
  236. 门店手机:
  237. {{ pickUpStoreList.find((p) => p.id === scope.row.pickUpStoreId)?.phone }}
  238. </span>
  239. <span>
  240. 自提门店:
  241. {{
  242. pickUpStoreList.find((p) => p.id === scope.row.pickUpStoreId)?.detailAddress
  243. }}
  244. </span>
  245. </div>
  246. </template>
  247. </el-table-column>
  248. <el-table-column align="center" label="配送方式" width="120">
  249. <template #default>
  250. <dict-tag :type="DICT_TYPE.TRADE_DELIVERY_TYPE" :value="scope.row.deliveryType" />
  251. </template>
  252. </el-table-column>
  253. <el-table-column align="center" label="订单状态" width="120">
  254. <template #default>
  255. <dict-tag :type="DICT_TYPE.TRADE_ORDER_STATUS" :value="scope.row.status" />
  256. </template>
  257. </el-table-column>
  258. <el-table-column align="center" fixed="right" label="操作" width="160">
  259. <template #default>
  260. <!-- TODO 权限后续补齐 -->
  261. <div class="flex justify-center items-center">
  262. <el-button link type="primary" @click="openForm(scope.row.id)">
  263. <Icon icon="ep:notification" />
  264. 详情
  265. </el-button>
  266. <el-dropdown @command="(command) => handleCommand(command, scope.row)">
  267. <el-button link type="primary">
  268. <Icon icon="ep:d-arrow-right" />
  269. 更多
  270. </el-button>
  271. <template #dropdown>
  272. <el-dropdown-menu>
  273. <!-- 如果是【快递】,并且【未发货】,则展示【发货】按钮 -->
  274. <el-dropdown-item
  275. v-if="scope.row.deliveryType === 1 && scope.row.status === 10"
  276. command="delivery"
  277. >
  278. <Icon icon="ep:takeaway-box" />
  279. 发货
  280. </el-dropdown-item>
  281. <el-dropdown-item command="remark">
  282. <Icon icon="ep:chat-line-square" /> 备注
  283. </el-dropdown-item>
  284. </el-dropdown-menu>
  285. </template>
  286. </el-dropdown>
  287. </div>
  288. </template>
  289. </el-table-column>
  290. </el-table>
  291. </template>
  292. </el-table-column>
  293. </el-table>
  294. <!-- 分页 -->
  295. <Pagination
  296. v-model:limit="queryParams.pageSize"
  297. v-model:page="queryParams.pageNo"
  298. :total="total"
  299. @pagination="getList"
  300. />
  301. </ContentWrap>
  302. <!-- 各种操作的弹窗 -->
  303. <OrderDeliveryForm ref="deliveryFormRef" @success="getList" />
  304. <OrderUpdateRemarkForm ref="updateRemarkForm" @success="getList" />
  305. </template>
  306. <script lang="ts" name="Order" setup>
  307. import type { FormInstance, TableColumnCtx } from 'element-plus'
  308. import OrderDeliveryForm from './components/OrderDeliveryForm.vue'
  309. import OrderUpdateRemarkForm from './components/OrderUpdateRemarkForm.vue'
  310. import * as TradeOrderApi from '@/api/mall/trade/order'
  311. import * as PickUpStoreApi from '@/api/mall/trade/delivery/pickUpStore'
  312. import { DICT_TYPE, getIntDictOptions, getStrDictOptions } from '@/utils/dict'
  313. import { formatDate } from '@/utils/formatTime'
  314. import { floatToFixed2 } from '@/utils'
  315. import { createImageViewer } from '@/components/ImageViewer'
  316. import * as DeliveryExpressApi from '@/api/mall/trade/delivery/express'
  317. const { currentRoute, push } = useRouter() // 路由跳转
  318. const loading = ref(true) // 列表的加载中
  319. const total = ref(2) // 列表的总页数
  320. const list = ref<TradeOrderApi.OrderVO[]>([]) // 列表的数据
  321. const queryFormRef = ref<FormInstance>() // 搜索的表单
  322. // 表单搜索
  323. const queryParams = reactive({
  324. pageNo: 1, //首页
  325. pageSize: 10, //页面大小
  326. no: '',
  327. userId: '',
  328. userNickname: '',
  329. userMobile: '',
  330. receiverName: '',
  331. receiverMobile: '',
  332. terminal: '',
  333. type: null,
  334. status: null,
  335. payChannelCode: '',
  336. createTime: [],
  337. spuName: '',
  338. itemCount: '',
  339. pickUpStoreId: [],
  340. logisticsId: null,
  341. all: ''
  342. })
  343. const queryType = reactive({ k: '', v: '' }) // 订单搜索类型kv
  344. /**
  345. * 订单聚合搜索
  346. * 商品名称、商品件数、全部
  347. *
  348. * 需要后端支持 TODO
  349. */
  350. const searchList = ref([
  351. { value: 'no', label: '订单号' },
  352. { value: 'userId', label: '用户UID' },
  353. { value: 'userNickname', label: '用户昵称' },
  354. { value: 'userMobile', label: '用户电话' }
  355. ])
  356. const headerStyle = ({ row, columnIndex }: any) => {
  357. // 表头第一行第一列占 8
  358. if (columnIndex === 0) {
  359. row[columnIndex].colSpan = 8
  360. } else {
  361. // 其余的不要
  362. row[columnIndex].colSpan = 0
  363. return {
  364. display: 'none'
  365. }
  366. }
  367. }
  368. interface SpanMethodProps {
  369. row: TradeOrderApi.OrderItemRespVO
  370. column: TableColumnCtx<TradeOrderApi.OrderItemRespVO>
  371. rowIndex: number
  372. columnIndex: number
  373. }
  374. const spanMethod = ({ row, rowIndex, columnIndex }: SpanMethodProps) => {
  375. const len = list.value.find(
  376. (order) => order.items?.findIndex((item) => item.id === row.id) !== -1
  377. )?.items?.length
  378. // 要合并的列,从零开始
  379. const colIndex = [3, 4, 5, 6]
  380. if (colIndex.includes(columnIndex)) {
  381. // 除了第一行其余的不要
  382. if (rowIndex !== 0) {
  383. return {
  384. rowspan: 0,
  385. colspan: 0
  386. }
  387. }
  388. // 动态合并行
  389. return {
  390. rowspan: len,
  391. colspan: 1
  392. }
  393. }
  394. }
  395. /** 查询列表 */
  396. const getList = async () => {
  397. loading.value = true
  398. try {
  399. const data = await TradeOrderApi.getOrderPage(queryParams)
  400. list.value = data.list
  401. total.value = data.total
  402. } finally {
  403. loading.value = false
  404. }
  405. }
  406. /** 搜索按钮操作 */
  407. const handleQuery = async () => {
  408. queryParams.pageNo = 1
  409. await getList()
  410. }
  411. /** 重置按钮操作 */
  412. const resetQuery = () => {
  413. queryFormRef.value?.resetFields()
  414. handleQuery()
  415. }
  416. /** 商品图预览 */
  417. const imagePreview = (imgUrl: string) => {
  418. createImageViewer({
  419. urlList: [imgUrl]
  420. })
  421. }
  422. /** 查看订单详情 */
  423. const openForm = (id: number) => {
  424. push({ name: 'TradeOrderDetailForm', params: { orderId: id } })
  425. }
  426. /** 操作分发 */
  427. const deliveryFormRef = ref()
  428. const updateRemarkForm = ref()
  429. const handleCommand = (command: string, row: TradeOrderApi.OrderVO) => {
  430. switch (command) {
  431. case 'remark':
  432. updateRemarkForm.value?.open(row)
  433. break
  434. case 'delivery':
  435. deliveryFormRef.value?.open(row)
  436. break
  437. }
  438. }
  439. // 监听路由变化更新列表,解决订单保存/更新后,列表不刷新的问题。
  440. watch(
  441. () => currentRoute.value,
  442. () => {
  443. getList()
  444. }
  445. )
  446. const pickUpStoreList = ref([]) // 自提门店精简列表
  447. const deliveryExpressList = ref([]) // 物流公司
  448. /** 初始化 **/
  449. onMounted(async () => {
  450. await getList()
  451. pickUpStoreList.value = await PickUpStoreApi.getListAllSimple()
  452. deliveryExpressList.value = await DeliveryExpressApi.getSimpleDeliveryExpressList()
  453. })
  454. </script>
  455. <style lang="scss" scoped>
  456. :deep(.order-table-col > .cell) {
  457. padding: 0;
  458. }
  459. </style>