index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <template>
  2. <div class="h-full flex">
  3. <div class="p-5 w-80 pr-0">
  4. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col">
  5. <div class="flex-1 p-3 overflow-y-auto">
  6. <!-- 筛选条件 -->
  7. <el-form :model="filterForm" label-width="70px" style="max-width: 600px">
  8. <template v-for="(item, index) in filterItems">
  9. <el-form-item :label="item.label" v-if="item.type != 'date'">
  10. <el-input v-if="item.type === 'input'" v-model="filterForm[item.key as keyof FilterForm]" clearable
  11. placeholder="请输入"></el-input>
  12. <el-select v-else v-model="filterForm[item.key as keyof FilterForm]" placeholder="请选择" clearable>
  13. <el-option v-for="option in item.options" :key="option.id" :label="option.name" :value="option.id" />
  14. </el-select>
  15. </el-form-item>
  16. <template v-if="item.type == 'date'">
  17. <el-form-item :label="item.label">
  18. <el-date-picker v-model="filterForm.startTime" type="date" placeholder="请选择" :clearable="false"
  19. format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  20. </el-form-item>
  21. <el-form-item label="">
  22. <el-date-picker v-model="filterForm.endTime" type="date" placeholder="请选择" :clearable="false"
  23. format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  24. </el-form-item>
  25. </template>
  26. </template>
  27. </el-form>
  28. </div>
  29. <div class="w-full flex p-3 shadow-[0_-3px_5px_0px_rgba(0,0,0,0.2)]">
  30. <El-button class="w-full" @click="resetFilterForm()">重置</El-Button>
  31. <El-button type="primary" class="w-full" @click="getTableList()">搜索</El-Button>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="flex-1 p-5 overflow-auto">
  36. <div class="bg-white w-full h-full p-3 shadow-md rounded-md flex flex-col">
  37. <div class="flex justify-end pb-3">
  38. <!-- 操作按钮 -->
  39. <el-button type="primary" v-permission="['orderAdd']" @click="editOrder(false)">新建订单</el-button>
  40. <el-button type="primary" :disabled="batchTableData.length <= 0">批量转移</el-button>
  41. <el-button type="primary" v-permission="['orderDelete']" @click="batchDeteleItem()" :disabled="batchTableData.length <= 0">批量删除</el-button>
  42. <el-button type="primary" v-permission="['orderRecycle']" @click="showVisible('deteleOrderVisible')">回收站</el-button>
  43. <el-button type="primary" v-permission="['orderImport']" @click="showVisible('importVisible')">导入</el-button>
  44. <el-button type="primary" v-permission="['orderExport']" @click="exportOrderTableList()" :loading="allLoading.exoprtLoading">导出</el-button>
  45. </div>
  46. <div class="flex-1 w-full overflow-hidden">
  47. <!-- 表格 -->
  48. <el-table ref="otherTableRef" :data="formTable" :show-overflow-tooltip="tableShowOverflowTooltip" border v-loading="allLoading.formTableLading"
  49. style="width: 100%;height: 100%;" @selection-change="changeBatch">
  50. <el-table-column type="selection" width="55" />
  51. <el-table-column v-for="(column, index) in tableColumns" :key="index" :prop="column.prop"
  52. :label="column.label" :width="column.width">
  53. <template #default="scope">
  54. <template v-if="column.event === 'toDetali'">
  55. <!-- <el-button link type="primary" size="large" @click="toDetali(scope.row)">{{ scope.row[column.prop]
  56. }}</el-button> -->
  57. <div class="table-text-textnowrap" @click.prevent="toDetali(scope.row)">{{ scope.row[column.prop] }}</div>
  58. </template>
  59. <template v-if="column.prop === 'receivedStatus'">
  60. <div>{{ selectData.RemittanceStatus[scope.row.receivedStatus].name }}</div>
  61. </template>
  62. </template>
  63. </el-table-column>
  64. <el-table-column :label="'操作'" :width="'200px'" fixed="right" v-permission="['orderEdit']">
  65. <template #default="scope">
  66. <el-button link type="primary" size="large" @click="editOrder(scope.row)">编辑</el-button>
  67. <el-button link type="primary" size="large" v-permission="['tasksEdit']" @click="newTask(scope.row)">新建任务</el-button>
  68. <el-button link type="danger" size="large" v-permission="['orderDelete']"
  69. @click="orderDeteleItem(scope.row.id, scope.row.orderName)">删除</el-button>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. </div>
  74. <div class="flex justify-end pt-3">
  75. <!-- 分页 -->
  76. <el-pagination layout="total, prev, pager, next, sizes" :total="formTablePaging.total"
  77. :hide-on-single-page="true" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  78. </div>
  79. </div>
  80. </div>
  81. <!-- 弹窗 -->
  82. <el-dialog v-model="allVisible.editOrderVisible" width="1000" :show-close="false" top="10vh">
  83. <template #header="{ close, titleId, titleClass }">
  84. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  85. <h4 :id="titleId">{{ allText.orderEditText }}</h4>
  86. <div>
  87. <el-button type="primary" :loading="allLoading.editSaveLading" v-if="!orderTemplateValue.id" @click="saveOrder(true)">保存并新建</el-button>
  88. <el-button type="primary" :loading="allLoading.editSaveLading" @click="saveOrder(false)">保存</el-button>
  89. <el-button @click="closeVisible('editOrderVisible')">取消</el-button>
  90. </div>
  91. </div>
  92. </template>
  93. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3" v-loading="allLoading.orderTemplateLoadinng">
  94. <GenerateForm ref="orderTemplateRef" :data="orderTemplate" :key="orderTemplateKey" :value="orderTemplateValue" />
  95. <div>相关产品</div>
  96. <RelatedProducts ref="relatedProductsRef" :productTableList="productTableList"
  97. :productTableListValue="productTableListValue" />
  98. </div>
  99. </el-dialog>
  100. <!-- 新建任务 -->
  101. <TaskModal :visible="allVisible.taskModalVisible" :edit-form="taskModalForm" :save-loading="taskLoading"
  102. @close="allVisible.taskModalVisible = false" @submit="submitForm" :title="'新建任务'"
  103. :disabled-list="['taskType', 'orderId']" />
  104. <!-- 回收站 -->
  105. <DeteleTables :visibles="allVisible.deteleOrderVisible" @closeVisible="closeVisible" />
  106. <!-- 导入 -->
  107. <el-dialog v-model="allVisible.importVisible" width="680" :show-close="false" top="10vh">
  108. <template #header="{ close, titleId, titleClass }">
  109. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  110. <h4 :id="titleId">导入联系人</h4>
  111. <div class="flex">
  112. <el-upload class="upload-demo mr-3" :limit="1" :show-file-list="false" accept=".xlsx"
  113. :http-request="importBusiness">
  114. <el-button type="primary" :loading="allLoading.importLoading">导入</el-button>
  115. </el-upload>
  116. <el-button @click="allVisible.importVisible = false">取消</el-button>
  117. </div>
  118. </div>
  119. </template>
  120. <div class="p-8">
  121. <div class="ml-4 mr-4">
  122. <div class="flex items-center">1、点击下载 <el-link type="primary"
  123. @click="downloadTemplate(IMPORTMOD, allText.importText)">{{ allText.importText }}</el-link></div>
  124. <div class="mt-4">2、填写excel文件、订单名称、客户名称、订单金额、负责人必填</div>
  125. </div>
  126. </div>
  127. </el-dialog>
  128. </div>
  129. </template>
  130. <script lang="ts" setup>
  131. import { ref, reactive, onMounted, inject, defineExpose } from "vue";
  132. import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, getLastDayOfMonth, formatDate, getTemplateKey, createTaskFromType, confirmAction, downloadFile, downloadTemplate } from '@/utils/tools'
  133. import { post, get, uploadFile } from "@/utils/request";
  134. import { tableColumns, GETSYSFILED, GETPERSONNEL, GETGENERATEFOEM, MOD, GETTABLELIST, GETALLPRODUCT, GETTABLELISTPRODUCT, URL_OEDERUPDATE, URL_PRODUTWITHORDER, URL_DETELEITEM, EXPORTTIME, IMPORTMOD, IMPORITEM, paymentStatus } from "./api";
  135. import { useRouter, useRoute } from "vue-router";
  136. import { GenerateForm } from '@zmjs/form-design';
  137. import { formatDateTime } from "@/utils/times";
  138. import { ElTable, UploadRequestOptions } from "element-plus";
  139. import { createTask } from "@/components/TaskModal/taskFunction";
  140. import { tableShowOverflowTooltip } from '@/utils/globalVariables'
  141. import { URL_FETALL } from "../customer/api";
  142. import RelatedProducts from '@/components/relatedProducts/relatedProducts.vue'
  143. import DeteleTables from './component/deteleTables.vue'
  144. import TaskModal from '@/components/TaskModal/index.vue'
  145. const router = useRouter()
  146. const globalPopup = inject<GlobalPopup>('globalPopup')
  147. const filterForm = reactive<FilterForm>({ // 筛选条件 Value
  148. contactPerson: "",
  149. customerId: "",
  150. phoneNumber: '',
  151. responsibleId: '',
  152. createId: '',
  153. email: '',
  154. startTime: getFirstDayOfMonth(new Date()),
  155. endTime: formatDate(new Date())
  156. });
  157. const selectData = reactive({ // 下拉数据
  158. Personnel: [] as personnelInterface[],
  159. Customer: [] as any[], // 客户名称
  160. OrderType: [] as any[], // 订单类型
  161. RemittanceStatus: [{ id: 0, name: '已回款' }, { id: 1, name: '未回款' }, { id: 2, name: '已完全回款' }] as any[], // 回款状态
  162. AllProduct: [] as any[] // 所有产品
  163. })
  164. const formTablePaging = reactive({ // 分页条件
  165. pageIndex: 1,
  166. pageSize: 10,
  167. total: 0,
  168. })
  169. const allLoading = reactive({ // 按钮加载 Loading
  170. formTableLading: false,
  171. editSaveLading: false,
  172. orderTemplateLoadinng: false,
  173. exoprtLoading: false,
  174. importLoading: false
  175. })
  176. const allVisible = reactive({
  177. editOrderVisible: false,
  178. taskModalVisible: false,
  179. deteleOrderVisible: false,
  180. importVisible: false
  181. })
  182. const allText = reactive({
  183. orderEditText: '新建订单',
  184. importText: '销售订单表导出.xlsx'
  185. })
  186. const orderTemplate = ref({
  187. list: [],
  188. config: {}
  189. })
  190. const filterItems = ref<FilterItem[]>([
  191. { label: '订单编号', key: 'orderCode', type: 'input' },
  192. { label: '订单名称', key: 'orderName', type: 'input' },
  193. { label: '客户名称', key: 'customId', type: 'select', options: selectData.Customer },
  194. { label: '商机名称', key: 'businessName', type: 'input' },
  195. { label: '订单类型', key: 'ordertype', type: 'select', options: selectData.OrderType },
  196. { label: '回款状态', key: 'receivedStatus', type: 'select', options: selectData.RemittanceStatus },
  197. { label: '负责人', key: 'inchargerId', type: 'select', options: selectData.Personnel },
  198. { label: '下单时间', key: '', type: 'date' },
  199. ]) // 渲染筛选条件
  200. const orderTemplateValue = ref<any>({})
  201. const orderTemplateKey = ref(1)
  202. const orderTemplateRef = ref<typeof GenerateForm>()
  203. const relatedProductsRef = ref<typeof RelatedProducts>()
  204. const otherTableRef = ref<InstanceType<typeof ElTable>>()
  205. const taskLoading = ref<saveLoadingType>('1')
  206. const batchTableData = ref([])
  207. const formTable = ref([]) // 表格数据
  208. const productTableList = ref([])
  209. const productTableListValue = ref([])
  210. const taskModalForm = ref({})
  211. async function importBusiness(param: UploadRequestOptions) {
  212. allLoading.importLoading = true
  213. const formData = new FormData();
  214. formData.append('multipartFile', param.file)
  215. const res = await uploadFile(IMPORITEM, formData).finally(() => {
  216. allLoading.importLoading = false
  217. })
  218. if (res.code == 'ok') {
  219. globalPopup?.showSuccess('导入成功' || '')
  220. getTableList()
  221. return
  222. }
  223. globalPopup?.showError(res.msg || '')
  224. }
  225. function exportOrderTableList() {
  226. allLoading.exoprtLoading = true
  227. let valueForm = getFromValue(filterForm)
  228. post(EXPORTTIME, {...valueForm}).then((res) => {
  229. downloadFile(res.data, allText.importText)
  230. }).finally(() => {
  231. allLoading.exoprtLoading = false
  232. })
  233. }
  234. function batchDeteleItem() {
  235. const value = batchTableData.value.map((item: any) => item.id).join(',')
  236. const label = batchTableData.value.map((item: any) => item.orderName).join(',')
  237. orderDeteleItem(value, label, true)
  238. }
  239. function orderDeteleItem(value: string | number, label: string, batch: boolean = false) {
  240. confirmAction(`确定${batch ? '批量' : ''}删除【${label}】销售订单吗?`).then(() => {
  241. post(URL_DETELEITEM, { ids: value }).then(res => {
  242. if (res.code != 'ok') {
  243. globalPopup?.showError(res.msg)
  244. return
  245. }
  246. globalPopup?.showSuccess('删除成功')
  247. changeBatch(false)
  248. getTableList()
  249. }).catch((err) => {
  250. globalPopup?.showError(err.msg)
  251. })
  252. })
  253. }
  254. function submitForm(submitData: any, isClose: boolean) {
  255. taskLoading.value = '2'
  256. createTask(submitData, isClose).then((res) => {
  257. const { saveLoading, isClose } = res
  258. taskLoading.value = saveLoading
  259. allVisible.taskModalVisible = isClose
  260. globalPopup?.showSuccess('新增成功')
  261. }).catch((err) => {
  262. const { saveLoading, isClose, message } = err
  263. taskLoading.value = saveLoading
  264. allVisible.taskModalVisible = isClose
  265. globalPopup?.showError(message)
  266. })
  267. }
  268. function newTask(item: any) {
  269. const { id } = item
  270. taskModalForm.value = { ...createTaskFromType(2), orderId: id, }
  271. allVisible.taskModalVisible = true
  272. }
  273. function saveOrder(flag: boolean) {
  274. orderTemplateRef.value?.getData().then((res: any) => {
  275. let productTableListData = relatedProductsRef?.value?.returnData()
  276. for (var i in productTableListData) {
  277. productTableListData[i].sealPrice = productTableListData[i].sellingPrice,
  278. productTableListData[i].discount = productTableListData[i].discount,
  279. productTableListData[i].num = productTableListData[i].quantity
  280. }
  281. const produt = productTableListData ? JSON.stringify(productTableListData) : []
  282. const formVal = {
  283. ...orderTemplateValue.value,
  284. ...res,
  285. orderEndDate: res.orderEndDate ? formatDate(res.orderEndDate) : '',
  286. orderStartDate: res.orderStartDate ? formatDate(res.orderStartDate) : '',
  287. placeTime: res.placeTime ? formatDate(res.placeTime) : '',
  288. orderProductDetailString: produt
  289. }
  290. console.log((formVal.price || 0), (formVal.receivedPayment || 0), (formVal.price || 0) < (formVal.receivedPayment || 0))
  291. if((formVal.price || 0) < (formVal.receivedPayment || 0)) {
  292. globalPopup?.showError('已回款金额不能大于订单金额')
  293. return
  294. }
  295. allLoading.editSaveLading = true
  296. post(URL_OEDERUPDATE, formVal).then((_res) => {
  297. allVisible.editOrderVisible = flag
  298. globalPopup?.showSuccess('保存成功')
  299. if (flag) {
  300. orderTemplateRef.value?.reset()
  301. }
  302. getTableList()
  303. }).finally(() => {
  304. allLoading.editSaveLading = false
  305. })
  306. }).catch((_err: any) => {
  307. globalPopup?.showError('请填写完整')
  308. })
  309. }
  310. function editOrder(item: any) {
  311. showVisible('editOrderVisible')
  312. allLoading.orderTemplateLoadinng = true
  313. if (item) {
  314. editProduct(item)
  315. const templateKey = getTemplateKey(orderTemplate.value.list)
  316. let formVal: templateKey = { id: item.id }
  317. for (let i = 0; i < templateKey.length; i++) {
  318. const key = templateKey[i]
  319. formVal[key] = item[key]
  320. }
  321. orderTemplateValue.value = formVal
  322. console.log(formVal, '<============ 数据')
  323. allText.orderEditText = '编辑订单'
  324. }
  325. if (!item) {
  326. orderTemplateValue.value = {}
  327. productTableListValue.value = []
  328. allText.orderEditText = '新增订单'
  329. }
  330. setTimeout(() => {
  331. orderTemplateRef.value && orderTemplateRef.value.reset()
  332. orderTemplateKey.value++
  333. allLoading.orderTemplateLoadinng = false
  334. }, 1000)
  335. }
  336. function toDetali(row: any) {
  337. router.push({
  338. path: `${MOD}/detail`,
  339. query: { id: row.id }
  340. })
  341. }
  342. function getTableList() {
  343. const formValue = getFromValue(filterForm)
  344. const formPaging = { pageIndex: formTablePaging.pageIndex, pageSize: formTablePaging.pageSize }
  345. allLoading.formTableLading = true
  346. post(GETTABLELIST, { ...formValue, ...formPaging }).then(res => {
  347. const { total, record } = res.data
  348. formTable.value = (record || []).map((item: any) => {
  349. let val = paymentStatus.find((items: any) => items.value == item.status)
  350. return {
  351. ...item,
  352. statusValue: val ? val.label : ''
  353. }
  354. })
  355. formTablePaging.total = total
  356. }).finally(() => {
  357. allLoading.formTableLading = false
  358. })
  359. }
  360. function resetFilterForm() {
  361. let newFilterForm = resetFromValue(filterForm, { startTime: getFirstDayOfMonth(new Date()), endTime: formatDate(new Date()) })
  362. Object.assign(filterForm, newFilterForm)
  363. getTableList()
  364. }
  365. function getAllProduct() {
  366. get(GETALLPRODUCT, { pageIndex: -1, pageSize: -1 }).then((res) => {
  367. const { record } = res.data
  368. selectData.AllProduct = record
  369. })
  370. }
  371. async function getSystemField() {
  372. const systemField = getAllListByCode(['订单类型'])
  373. for (let i in systemField) {
  374. const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
  375. for (let key of Object.keys(selectData)) {
  376. if (systemField[i] == key) {
  377. Object.assign(selectData, { [key]: data })
  378. }
  379. }
  380. }
  381. const { data: personnelData } = await post(GETPERSONNEL, {})
  382. selectData.Personnel = personnelData.map((item: any) => {
  383. const { id, name, phone, jobNumber } = item
  384. return { id, name, phone, jobNumber }
  385. })
  386. const { data: customerData } = await post(URL_FETALL, {})
  387. selectData.Customer = (customerData || []).map((item: any) => {
  388. const { id, customName } = item
  389. return { id, name: customName }
  390. })
  391. const res = await get(GETGENERATEFOEM)
  392. orderTemplate.value = JSON.parse(res.data[0].config)
  393. setFilterItems()
  394. }
  395. function changeBatch(flag: boolean = true) {
  396. if (flag) {
  397. batchTableData.value = otherTableRef.value && otherTableRef.value.getSelectionRows()
  398. } else {
  399. batchTableData.value = []
  400. otherTableRef.value && otherTableRef.value.clearSelection()
  401. }
  402. }
  403. function showVisible(type: keyof typeof allVisible) { // 显示弹窗
  404. allVisible[type] = true
  405. }
  406. function closeVisible(type: keyof typeof allVisible) {
  407. allVisible[type] = false
  408. }
  409. function setFilterItems() {
  410. filterItems.value = [
  411. { label: '订单编号', key: 'orderCode', type: 'input' },
  412. { label: '订单名称', key: 'orderName', type: 'input' },
  413. { label: '客户名称', key: 'customId', type: 'select', options: selectData.Customer },
  414. { label: '商机名称', key: 'businessName', type: 'input' },
  415. { label: '订单类型', key: 'orderType', type: 'select', options: selectData.OrderType },
  416. { label: '回款状态', key: 'receivedStatus', type: 'select', options: selectData.RemittanceStatus },
  417. { label: '负责人', key: 'inchargerId', type: 'select', options: selectData.Personnel },
  418. { label: '下单时间', key: '', type: 'date' },
  419. ]
  420. }
  421. function editProduct(row: any) {
  422. post(URL_PRODUTWITHORDER, { id: row.id }).then(({ data }) => {
  423. const list = data.map((item: any) => {
  424. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory, orderProductDetail } = item
  425. return {
  426. id, productId: id, productName, productCode, unit, unitName, typeName, type, price, inventory,
  427. quantity: +orderProductDetail?.num,
  428. discount: +orderProductDetail?.discount,
  429. sellingPrice: +orderProductDetail?.sealPrice,
  430. totalPrice: +orderProductDetail?.totalPrice
  431. }
  432. })
  433. productTableListValue.value = list
  434. })
  435. }
  436. function getProductTableList() {
  437. post(GETTABLELISTPRODUCT, { pageIndex: -1, pageSize: -1 }).then((res) => {
  438. if (res.code == 'ok') {
  439. const { record, total } = res.data
  440. productTableList.value = record.map((item: any) => {
  441. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  442. return {
  443. id,
  444. productId: id,
  445. productName,
  446. productCode,
  447. unit,
  448. unitName,
  449. price,
  450. type,
  451. typeName,
  452. inventory,
  453. quantity: '',
  454. discount: '',
  455. totalPrice: ''
  456. }
  457. })
  458. }
  459. })
  460. }
  461. function handleSizeChange(val: number) {
  462. formTablePaging.pageIndex = 1
  463. formTablePaging.pageSize = val
  464. getTableList()
  465. }
  466. function handleCurrentChange(val: number) {
  467. formTablePaging.pageIndex = val
  468. getTableList()
  469. }
  470. onMounted(() => {
  471. getSystemField()
  472. getAllProduct()
  473. getTableList()
  474. getProductTableList()
  475. })
  476. </script>
  477. <style lang="scss" scoped></style>