index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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]" v-if="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. importText: '销售订单表导入.xlsx'
  193. })
  194. const orderTemplate = ref({
  195. list: [],
  196. config: {}
  197. })
  198. const filterItems = ref<FilterItem[]>([
  199. { label: '订单编号', key: 'orderCode', type: 'input' },
  200. { label: '订单名称', key: 'orderName', type: 'input' },
  201. { label: '客户名称', key: 'customId', type: 'select', options: selectData.Customer },
  202. { label: '商机名称', key: 'businessName', type: 'input' },
  203. { label: '订单类型', key: 'ordertype', type: 'select', options: selectData.OrderType },
  204. { label: '回款状态', key: 'receivedStatus', type: 'select', options: selectData.RemittanceStatus },
  205. { label: '负责人', key: 'inchargerId', type: 'select', options: selectData.Personnel },
  206. { label: '下单时间', key: '', type: 'date' },
  207. ]) // 渲染筛选条件
  208. const orderTemplateValue = ref<any>({})
  209. const orderTemplateKey = ref(1)
  210. const orderTemplateRef = ref<typeof GenerateForm>()
  211. const relatedProductsRef = ref<typeof RelatedProducts>()
  212. const otherTableRef = ref<InstanceType<typeof ElTable>>()
  213. const taskLoading = ref<saveLoadingType>('1')
  214. const batchTableData = ref([])
  215. const formTable = ref([]) // 表格数据
  216. const productTableList = ref([])
  217. const productTableListValue = ref([])
  218. const taskModalForm = ref({})
  219. async function importBusiness(param: UploadRequestOptions) {
  220. allLoading.importLoading = true
  221. const formData = new FormData();
  222. formData.append('multipartFile', param.file)
  223. const res = await uploadFile(IMPORITEM, formData).finally(() => {
  224. allLoading.importLoading = false
  225. })
  226. if (res.code == 'ok') {
  227. globalPopup?.showSuccess('导入成功' || '')
  228. getTableList()
  229. return
  230. }
  231. globalPopup?.showError(res.msg || '')
  232. }
  233. function exportOrderTableList() {
  234. allLoading.exoprtLoading = true
  235. let valueForm = getFromValue(filterForm)
  236. post(EXPORTTIME, {...valueForm}).then((res) => {
  237. downloadFile(res.data, allText.importText)
  238. }).finally(() => {
  239. allLoading.exoprtLoading = false
  240. })
  241. }
  242. function batchDeteleItem() {
  243. const value = batchTableData.value.map((item: any) => item.id).join(',')
  244. const label = batchTableData.value.map((item: any) => item.orderName).join(',')
  245. orderDeteleItem(value, label, true)
  246. }
  247. function orderDeteleItem(value: string | number, label: string, batch: boolean = false) {
  248. confirmAction(`确定${batch ? '批量' : ''}删除【${label}】销售订单吗?`).then(() => {
  249. post(URL_DETELEITEM, { ids: value }).then(res => {
  250. if (res.code != 'ok') {
  251. globalPopup?.showError(res.msg)
  252. return
  253. }
  254. globalPopup?.showSuccess('删除成功')
  255. changeBatch(false)
  256. getTableList()
  257. }).catch((err) => {
  258. globalPopup?.showError(err.msg)
  259. })
  260. })
  261. }
  262. function submitForm(submitData: any, isClose: boolean) {
  263. taskLoading.value = '2'
  264. createTask(submitData, isClose).then((res) => {
  265. const { saveLoading, isClose } = res
  266. taskLoading.value = saveLoading
  267. allVisible.taskModalVisible = isClose
  268. globalPopup?.showSuccess('新增成功')
  269. }).catch((err) => {
  270. const { saveLoading, isClose, message } = err
  271. taskLoading.value = saveLoading
  272. allVisible.taskModalVisible = isClose
  273. globalPopup?.showError(message)
  274. })
  275. }
  276. function newTask(item: any) {
  277. const { id } = item
  278. taskModalForm.value = { ...createTaskFromType(2), orderId: id, }
  279. allVisible.taskModalVisible = true
  280. }
  281. function saveOrder(flag: boolean) {
  282. orderTemplateRef.value?.getData().then((res: any) => {
  283. let productTableListData = relatedProductsRef?.value?.returnData()
  284. for (var i in productTableListData) {
  285. productTableListData[i].sealPrice = productTableListData[i].sellingPrice,
  286. productTableListData[i].discount = productTableListData[i].discount,
  287. productTableListData[i].num = productTableListData[i].quantity
  288. }
  289. const produt = productTableListData ? JSON.stringify(productTableListData) : []
  290. const formVal = {
  291. ...orderTemplateValue.value,
  292. ...res,
  293. orderEndDate: res.orderEndDate ? formatDate(res.orderEndDate) : '',
  294. orderStartDate: res.orderStartDate ? formatDate(res.orderStartDate) : '',
  295. placeTime: res.placeTime ? formatDate(res.placeTime) : '',
  296. orderProductDetailString: produt
  297. }
  298. console.log((formVal.price || 0), (formVal.receivedPayment || 0), (formVal.price || 0) < (formVal.receivedPayment || 0))
  299. if((formVal.price || 0) < (formVal.receivedPayment || 0)) {
  300. globalPopup?.showError('已回款金额不能大于订单金额')
  301. return
  302. }
  303. allLoading.editSaveLading = true
  304. post(URL_OEDERUPDATE, formVal).then((_res) => {
  305. allVisible.editOrderVisible = flag
  306. globalPopup?.showSuccess('保存成功')
  307. if (flag) {
  308. orderTemplateRef.value?.reset()
  309. }
  310. getTableList()
  311. }).finally(() => {
  312. allLoading.editSaveLading = false
  313. })
  314. }).catch((_err: any) => {
  315. globalPopup?.showError('请填写完整')
  316. })
  317. }
  318. function editOrder(item: any) {
  319. showVisible('editOrderVisible')
  320. allLoading.orderTemplateLoadinng = true
  321. if (item) {
  322. editProduct(item)
  323. const templateKey = getTemplateKey(orderTemplate.value.list)
  324. let formVal: templateKey = { id: item.id }
  325. for (let i = 0; i < templateKey.length; i++) {
  326. const key = templateKey[i]
  327. formVal[key] = item[key]
  328. }
  329. orderTemplateValue.value = formVal
  330. console.log(formVal, '<============ 数据')
  331. allText.orderEditText = '编辑订单'
  332. }
  333. if (!item) {
  334. orderTemplateValue.value = {}
  335. productTableListValue.value = []
  336. allText.orderEditText = '新增订单'
  337. }
  338. setTimeout(() => {
  339. orderTemplateRef.value && orderTemplateRef.value.reset()
  340. orderTemplateKey.value++
  341. allLoading.orderTemplateLoadinng = false
  342. }, 1000)
  343. }
  344. function toDetali(row: any) {
  345. router.push({
  346. path: `${MOD}/detail`,
  347. query: { id: row.id }
  348. })
  349. }
  350. function getTableList() {
  351. const formValue = getFromValue(filterForm)
  352. const formPaging = { pageIndex: formTablePaging.pageIndex, pageSize: formTablePaging.pageSize }
  353. allLoading.formTableLading = true
  354. post(GETTABLELIST, { ...formValue, ...formPaging }).then(res => {
  355. const { total, record } = res.data
  356. formTable.value = (record || []).map((item: any) => {
  357. let val = paymentStatus.find((items: any) => items.value == item.status)
  358. return {
  359. ...item,
  360. statusValue: val ? val.label : ''
  361. }
  362. })
  363. formTablePaging.total = total
  364. }).finally(() => {
  365. allLoading.formTableLading = false
  366. })
  367. }
  368. function resetFilterForm() {
  369. let newFilterForm = resetFromValue(filterForm, { startTime: getFirstDayOfMonth(new Date()), endTime: formatDate(new Date()) })
  370. Object.assign(filterForm, newFilterForm)
  371. getTableList()
  372. }
  373. function getAllProduct() {
  374. get(GETALLPRODUCT, { pageIndex: -1, pageSize: -1 }).then((res) => {
  375. const { record } = res.data
  376. selectData.AllProduct = record
  377. })
  378. }
  379. async function getSystemField() {
  380. const systemField = getAllListByCode(['订单类型'])
  381. for (let i in systemField) {
  382. const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
  383. for (let key of Object.keys(selectData)) {
  384. if (systemField[i] == key) {
  385. Object.assign(selectData, { [key]: data })
  386. }
  387. }
  388. }
  389. const { data: personnelData } = await post(GETPERSONNEL, {})
  390. selectData.Personnel = personnelData.map((item: any) => {
  391. const { id, name, phone, jobNumber } = item
  392. return { id, name, phone, jobNumber }
  393. })
  394. const { data: customerData } = await post(URL_FETALL, {})
  395. selectData.Customer = (customerData || []).map((item: any) => {
  396. const { id, customName } = item
  397. return { id, name: customName }
  398. })
  399. const res = await get(GETGENERATEFOEM)
  400. orderTemplate.value = JSON.parse(res.data[0].config)
  401. setFilterItems()
  402. }
  403. function changeBatch(flag: boolean = true) {
  404. if (flag) {
  405. batchTableData.value = otherTableRef.value && otherTableRef.value.getSelectionRows()
  406. } else {
  407. batchTableData.value = []
  408. otherTableRef.value && otherTableRef.value.clearSelection()
  409. }
  410. }
  411. function showVisible(type: keyof typeof allVisible) { // 显示弹窗
  412. allVisible[type] = true
  413. }
  414. function closeVisible(type: keyof typeof allVisible) {
  415. allVisible[type] = false
  416. }
  417. function setFilterItems() {
  418. filterItems.value = [
  419. { label: '订单编号', key: 'orderCode', type: 'input' },
  420. { label: '订单名称', key: 'orderName', type: 'input' },
  421. { label: '客户名称', key: 'customId', type: 'select', options: selectData.Customer },
  422. { label: '商机名称', key: 'businessName', type: 'input' },
  423. { label: '订单类型', key: 'orderType', type: 'select', options: selectData.OrderType },
  424. { label: '回款状态', key: 'receivedStatus', type: 'select', options: selectData.RemittanceStatus },
  425. { label: '负责人', key: 'inchargerId', type: 'select', options: selectData.Personnel },
  426. { label: '下单时间', key: '', type: 'date' },
  427. ]
  428. }
  429. function editProduct(row: any) {
  430. post(URL_PRODUTWITHORDER, { id: row.id }).then(({ data }) => {
  431. const list = data.map((item: any) => {
  432. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory, orderProductDetail } = item
  433. return {
  434. id, productId: id, productName, productCode, unit, unitName, typeName, type, price, inventory,
  435. quantity: +orderProductDetail?.num,
  436. discount: +orderProductDetail?.discount,
  437. sellingPrice: +orderProductDetail?.sealPrice,
  438. totalPrice: +orderProductDetail?.totalPrice
  439. }
  440. })
  441. productTableListValue.value = list
  442. })
  443. }
  444. function getProductTableList() {
  445. post(GETTABLELISTPRODUCT, { pageIndex: -1, pageSize: -1 }).then((res) => {
  446. if (res.code == 'ok') {
  447. const { record, total } = res.data
  448. productTableList.value = record.map((item: any) => {
  449. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  450. return {
  451. id,
  452. productId: id,
  453. productName,
  454. productCode,
  455. unit,
  456. unitName,
  457. price,
  458. type,
  459. typeName,
  460. inventory,
  461. quantity: '',
  462. discount: '',
  463. totalPrice: ''
  464. }
  465. })
  466. }
  467. })
  468. }
  469. function handleSizeChange(val: number) {
  470. formTablePaging.pageIndex = 1
  471. formTablePaging.pageSize = val
  472. getTableList()
  473. }
  474. function handleCurrentChange(val: number) {
  475. formTablePaging.pageIndex = val
  476. getTableList()
  477. }
  478. onMounted(() => {
  479. getSystemField()
  480. getAllProduct()
  481. getTableList()
  482. getProductTableList()
  483. })
  484. </script>
  485. <style lang="scss" scoped></style>