index.vue 21 KB

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