order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <div>
  3. <ul class="flex space-x-2 rtl:space-x-reverse">
  4. <li>
  5. <a href="javascript:;" class=" hover:underline" @click="goHome">首页</a>
  6. </li>
  7. <li class="before:content-['/'] ltr:before:mr-2 rtl:before:ml-2 text-primary hover:underline">
  8. <span>订单列表</span>
  9. </li>
  10. </ul>
  11. <div class="panel pb-0 mt-6">
  12. <div class="flex md:items-center md:flex-row flex-col mb-5 gap-5">
  13. <div class="flex items-center gap-5 ltr:ml-auto rtl:mr-auto">
  14. <div class="dropdown">
  15. <Popper :placement="store.rtlClass === 'rtl' ? 'bottom-end' : 'bottom-start'" offsetDistance="0"
  16. class="align-middle">
  17. <button type="button"
  18. class="flex items-center border font-semibold
  19. border-[#e0e6ed] dark:border-[#253b5c]
  20. rounded-md px-4 py-2 text-sm dark:bg-[#1b2e4b] dark:text-white-dark whitespace-nowrap">
  21. <span class="ltr:mr-1 rtl:ml-1 inline">选择</span>
  22. <icon-caret-down class="w-5 h-5" />
  23. </button>
  24. <!-- <button type="button"
  25. style="white-space: nowrap; flex-wrap: nowrap; display: flex; align-items: center; border: 1px solid #e0e6ed; border-radius: 4px; padding: 8px 16px; font-weight: 600; background-color: transparent; text-align: left; color: inherit;">
  26. <span style="margin-right: 8px;">选择</span>
  27. <i class="icon-caret-down" style="width: 5px; height: 5px;"></i>
  28. </button> -->
  29. <template #content>
  30. <ul class="whitespace-nowrap">
  31. <template v-for="(col, i) in cols" :key="i">
  32. <li>
  33. <div class="flex items-center px-4 py-1">
  34. <label class="cursor-pointer mb-0">
  35. <input type="checkbox" class="form-checkbox" :id="`chk-${i}`"
  36. :value="col.field" @change="col.hide = !$event.target.checked"
  37. :checked="!col.hide" />
  38. <span :for="`chk-${i}`" class="ltr:ml-2 rtl:mr-2">{{ col.title
  39. }}</span>
  40. </label>
  41. </div>
  42. </li>
  43. </template>
  44. </ul>
  45. </template>
  46. </Popper>
  47. </div>
  48. <div>
  49. <input v-model="search" type="text" class="form-input" placeholder="Search..." />
  50. </div>
  51. </div>
  52. </div>
  53. <div class="datatable">
  54. <vue3-datatable :rows="rows" :columns="cols" :totalRows="rows?.length" :sortable="true" :search="search"
  55. skin="whitespace-nowrap bh-table-hover"
  56. firstArrow='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="w-4.5 h-4.5 rtl:rotate-180"> <path d="M13 19L7 12L13 5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> <path opacity="0.5" d="M16.9998 19L10.9998 12L16.9998 5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>'
  57. lastArrow='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="w-4.5 h-4.5 rtl:rotate-180"> <path d="M11 19L17 12L11 5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> <path opacity="0.5" d="M6.99976 19L12.9998 12L6.99976 5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg> '
  58. previousArrow='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="w-4.5 h-4.5 rtl:rotate-180"> <path d="M15 5L9 12L15 19" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>'
  59. nextArrow='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="w-4.5 h-4.5 rtl:rotate-180"> <path d="M9 5L15 12L9 19" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>'>
  60. <template #order_vo.order_time="data">
  61. {{ formatDate(data.value.order_vo.order_time) }}
  62. </template>
  63. <template #order_vo.member_id="data">
  64. {{ customerName(data.value.order_vo.member_id) }}
  65. </template>
  66. <template #warehouse_id="data">
  67. {{ warehouseName(data.value.warehouse_id) }}
  68. </template>
  69. <template #order_vo.pay_type="data">
  70. {{ collectingAccountName(data.value.order_vo.pay_type) }}
  71. </template>
  72. <template #order_vo.send_type="data">
  73. {{ deliveryName(data.value.order_vo.send_type) }}
  74. </template>
  75. <template #order_vo.status="data">
  76. {{ orderTypeName(data.value.order_vo.status) }}
  77. </template>
  78. <!-- 定义操作栏的模板 -->
  79. <template #actions="data">
  80. <button v-if="data.value.status !== 'SENDING'" @click="deliveryOrder(data)"
  81. class="btn btn-primary">发货</button>
  82. </template>
  83. <template #isActive="data">
  84. <!-- <span class="capitalize" :class="data.value.isActive ? 'text-success' : 'text-danger'">{{
  85. data._rawValue }}</span> -->
  86. </template>
  87. </vue3-datatable>
  88. <el-pagination class="p-2 flex justify-end dark:bg-[#0e1726]" v-model:current-page="params.page_no" :page-size="params.page_size" :small="true"
  89. layout="total, prev, pager, next" :total="totalRows" @size-change="handleSizeChange"
  90. @current-change="handleCurrentChange" />
  91. </div>
  92. </div>
  93. </div>
  94. </template>
  95. <script setup lang="ts">
  96. import { ref, onMounted } from 'vue';
  97. import Vue3Datatable from '@bhplugin/vue3-datatable';
  98. import { useAppStore } from '@/stores/index';
  99. import { useRouter } from 'vue-router';
  100. import { useMeta } from '@/composables/use-meta';
  101. import { orderApi, infoApi, dictionaryAPI } from '@/api/api'
  102. import IconBell from '@/components/icon/icon-bell.vue';
  103. import IconCaretDown from '@/components/icon/icon-caret-down.vue';
  104. useMeta({ title: 'Column Chooser Table' });
  105. const router = useRouter();
  106. const store = useAppStore();
  107. const search = ref('');
  108. const rows: any = ref([]); // 初始化rows为响应式引用
  109. const customerList: any = ref([])//初始化客户列表
  110. const warehouseList: any = ref([])//初始化客户列表
  111. const collectingAccountList: any = ref([])//初始化客户列表
  112. const deliveryList: any = ref([])//初始化客户列表
  113. const orderTypeList: any = ref([])//初始化客户列表
  114. const cols: any = ref([
  115. { field: 'sn', title: '订单编号', isUnique: true, hide: false },
  116. { field: 'order_vo.member_id', title: '客户', hide: false },
  117. { field: 'order_vo.order_time', title: '下单时间', hide: false },
  118. { field: 'warehouse_id', title: '仓库名称', hide: false },
  119. { field: 'order_vo.send_type', title: '配送方式', hide: false },
  120. { field: 'order_vo.pay_type', title: '付款方式', hide: false },
  121. /* { field: 'pay_price', title: '实付金额', hide: false }, */
  122. { field: 'order_vo.status', title: '订单状态', type: '', hide: true },
  123. /* { field: 'extension', title: '延期次数', type: '', hide: true },
  124. { field: 'type', title: '订单类型', type: '', hide: true }, */
  125. { field: 'actions', title: '操作', hide: false }
  126. ]);
  127. /* 处理订单时间格式 */
  128. const formatDate = (date) => {
  129. if (date) {
  130. const dt = new Date(date * 1000);
  131. const month = dt.getMonth() + 1 < 10 ? '0' + (dt.getMonth() + 1) : dt.getMonth() + 1;
  132. const day = dt.getDate() < 10 ? '0' + dt.getDate() : dt.getDate();
  133. return dt.getFullYear() + '/' + month + '/' + day;
  134. }
  135. return '';
  136. };
  137. /* 处理客户名称 */
  138. const customerName = (value) => {
  139. if (value && customerList.value && customerList.value.data && customerList.value.data.data) {
  140. const type = customerList.value.data.data.find(type => type.id === value);
  141. return type ? type.name : '';
  142. }
  143. }
  144. /* 仓库名称 */
  145. const warehouseName = (value) => {
  146. if (value && warehouseList.value && warehouseList.value.data) {
  147. const type = warehouseList.value.data.find(type => type.id === value);
  148. return type ? type.name : '';
  149. }
  150. }
  151. /* 支付列表*/
  152. const collectingAccountName = (value) => {
  153. if (value && collectingAccountList.value && collectingAccountList.value.data && collectingAccountList.value.data.data) {
  154. const type = collectingAccountList.value.data.data.find(type => type.id === value);
  155. return type ? type.name : '';
  156. }
  157. }
  158. /* 配送方式*/
  159. const deliveryName = (value) => {
  160. if (value && deliveryList.value && deliveryList.value.data && deliveryList.value.data.data) {
  161. const type = deliveryList.value.data.data.find(type => type.value === value);
  162. return type ? type.label : '';
  163. }
  164. }
  165. /* 订单状态*/
  166. const orderTypeName = (value) => {
  167. if (value && orderTypeList.value && orderTypeList.value.data && orderTypeList.value.data.data) {
  168. const type = orderTypeList.value.data.data.find(type => type.value === value);
  169. return type ? type.label : '';
  170. }
  171. }
  172. const params: any = ref([
  173. { page_no: 1, page_size: 10 }
  174. ])
  175. const totalRows: any = ref(0);
  176. const handleSizeChange = (val: number) => {
  177. console.log(`${val} items per page`)
  178. }
  179. const handleCurrentChange = (val: number) => {
  180. params.page_no = val
  181. getOrderList()
  182. console.log(`current page: ${val}`)
  183. }
  184. onMounted(() => {
  185. getOrderList()
  186. getInforList()
  187. });
  188. /* 获取订单列表的值 */
  189. const getOrderList = async () => {
  190. orderApi.orderList({ page_no:params.page_no,page_size:params.page_size, selectType: 'to_be_send' }).then((res: any) => {
  191. params.page_no = res.data.current
  192. params.page_size = res.data.size
  193. totalRows.value = res.data.total
  194. console.log(res);
  195. rows.value = res.data.records; // 更新rows的值
  196. });
  197. };
  198. /* 获取仓库,字典,客户信息 */
  199. const getInforList = async () => {
  200. warehouseList.value = await infoApi.warehouseList({})//获取仓库列表
  201. customerList.value = await infoApi.customer({})//获取客户列表
  202. collectingAccountList.value = await infoApi.collectingAccount({})//获取支付方式列表
  203. deliveryList.value = await dictionaryAPI.getPage({ dictType: "order_send_type" })//获取配送方式
  204. orderTypeList.value = await dictionaryAPI.getPage({ dictType: "Sale_order_send_status" })//获取订单状态
  205. }
  206. const deliveryOrder = async (row) => {
  207. router.replace({
  208. name: 'shippingPage',
  209. params: { id: row.value.id, send_type: row.value.order_vo.send_type }
  210. });
  211. }
  212. const goHome = () => {
  213. router.replace({
  214. name: 'home'
  215. });
  216. }
  217. </script>
  218. <style>
  219. .bh-pagination {
  220. display: none !important;
  221. }
  222. </style>