list.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <div class="bg-white page-indent-list py-4 px-2 shadow max-w-[1800px] mx-auto">
  3. <el-form
  4. ref="searchForm"
  5. :inline="true"
  6. :model="form"
  7. label-width="110px"
  8. >
  9. <div class="flex flex-wrap items-center search-form">
  10. <el-form-item :label="$t(prefix + 'label_Vendor_Name') + ':'">
  11. <el-input v-model="form.Vendor_Name"></el-input>
  12. </el-form-item>
  13. <el-form-item :label="$t(prefix + 'label_Payment_Terms') + ':'">
  14. <el-select
  15. v-model="form.Payment_Terms"
  16. clearable
  17. >
  18. <el-option
  19. v-for="item in categoryList"
  20. :key="item"
  21. :label="item"
  22. :value="item"
  23. ></el-option>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item :label="$t(prefix + 'label_status') + ':'">
  27. <el-select
  28. v-model="form.status"
  29. clearable
  30. >
  31. <el-option
  32. v-for="item in statusList"
  33. :key="item.value"
  34. :label="item.label"
  35. :value="item.value"
  36. ></el-option>
  37. </el-select>
  38. </el-form-item>
  39. <el-form-item>
  40. <div class="flex items-center btn-group">
  41. <el-button
  42. size="small"
  43. type="primary"
  44. @click="search"
  45. >
  46. {{ $t('btn_query') }}
  47. </el-button>
  48. <el-button
  49. size="small"
  50. type="default"
  51. @click="reset"
  52. >
  53. {{ $t('btn_reset') }}
  54. </el-button>
  55. </div>
  56. </el-form-item>
  57. </div>
  58. </el-form>
  59. <div class="mb-2 flex justify-between">
  60. <el-button
  61. size="small"
  62. type="primary"
  63. @click="componentEditVisible = 1"
  64. >
  65. {{ $t('btn_add') }}
  66. </el-button>
  67. <el-form inline>
  68. <el-form-item label="审核人:">
  69. <el-select
  70. v-model="auditUser"
  71. class="min-w-[200px]"
  72. filterable
  73. :loading="setAuditUserLoading"
  74. placeholder="可搜索"
  75. size="small"
  76. >
  77. <el-option
  78. v-for="user in userList"
  79. :key="user.id"
  80. :value="user.id"
  81. :label="`${user.name} (${user.username})`"
  82. ></el-option>
  83. </el-select>
  84. </el-form-item>
  85. <el-form-item>
  86. <el-tooltip content="保存审核人">
  87. <el-button
  88. type="primary"
  89. size="small"
  90. :loading="setAuditUserLoading"
  91. @click="setAuditUser"
  92. >
  93. 保存
  94. </el-button>
  95. </el-tooltip>
  96. </el-form-item>
  97. </el-form>
  98. </div>
  99. <el-table
  100. ref="tableIndent"
  101. :header-cell-style="{ backgroundColor: '#F2F6FC' }"
  102. :row-style="{ backgroundColor: '#F2F6FC' }"
  103. :data="list"
  104. default-expand-all
  105. border
  106. >
  107. <el-table-column type="index"></el-table-column>
  108. <el-table-column
  109. v-for="value in mainTableConfig"
  110. :key="value.field"
  111. :align="value.align || 'center'"
  112. :width="value.width || ''"
  113. :prop="value.field"
  114. :label="$t(value.label)"
  115. >
  116. <template #default="scope">
  117. <div v-if="value.type === 'imageList'">
  118. <img
  119. v-if="scope.row[value.field].length"
  120. style="width: 100%"
  121. :src="scope.row[value.field][0]"
  122. @click="imgClick(scope.row[value.field][0])"
  123. />
  124. </div>
  125. <div v-else-if="value.field === 'status'">
  126. <div>
  127. {{ getStatusLabel(scope.row[value.field]) }}
  128. </div>
  129. <el-button
  130. size="small"
  131. type="primary"
  132. link
  133. @click="openRecord(scope.row)"
  134. >
  135. {{ $t(prefix + 'label_audit_detail') }}
  136. </el-button>
  137. </div>
  138. <div
  139. v-else
  140. class="table-cell-content"
  141. :style="value.style || {}"
  142. >
  143. {{ scope.row[value.field] }}
  144. </div>
  145. </template>
  146. </el-table-column>
  147. <el-table-column
  148. prop="status"
  149. width="220"
  150. :label="$t('table_operation')"
  151. >
  152. <template #default="scope">
  153. <el-button
  154. size="small"
  155. type="primary"
  156. :disabled="scope.row.status === 0"
  157. @click="edit(scope.row)"
  158. >
  159. {{ $t('btn_edit') }}
  160. </el-button>
  161. <el-button
  162. size="small"
  163. type="warning"
  164. :disabled="scope.row.status !== 0"
  165. @click="examine(scope.row)"
  166. >
  167. {{ $t('btn_audit') }}
  168. </el-button>
  169. <el-button
  170. :disabled="scope.row.status !== 2"
  171. size="small"
  172. type="danger"
  173. @click="deleteSupplierFunc(scope.row)"
  174. >
  175. {{ $t('btn_delete') }}
  176. </el-button>
  177. </template>
  178. </el-table-column>
  179. </el-table>
  180. <div class="flex justify-end my-4">
  181. <el-pagination
  182. v-show="total > 0"
  183. v-model:current-page="pageForm.page"
  184. v-model:page-size="pageForm.limit"
  185. v-model:total="total"
  186. layout="total, prev, pager, next, jumper, sizes"
  187. @current-change="getList"
  188. @size-change="getList"
  189. />
  190. </div>
  191. <comp-edit
  192. v-model:visible="componentEditVisible"
  193. :item-data="dataForEdit"
  194. :category-data="categoryList"
  195. :currency-data="currencyList"
  196. @update:visible="getList"
  197. ></comp-edit>
  198. <comp-record
  199. :id="recordId"
  200. v-model:visible="componentRecordVisible"
  201. :status-list="statusList"
  202. ></comp-record>
  203. <el-dialog
  204. v-model="bigImageVisible"
  205. style="margin: 5vh auto"
  206. width="800"
  207. >
  208. <div class="flex justify-center">
  209. <img
  210. :src="currentBigImage"
  211. style="max-width: 100%; height: auto"
  212. alt=""
  213. />
  214. </div>
  215. </el-dialog>
  216. </div>
  217. </template>
  218. <script lang="ts" setup>
  219. import { defineComponent, ref, watch } from 'vue'
  220. import {
  221. ElButton,
  222. ElForm,
  223. ElFormItem,
  224. ElInput,
  225. ElTable,
  226. ElTableColumn,
  227. ElSelect,
  228. ElOption,
  229. ElMessageBox,
  230. ElNotification,
  231. ElPagination,
  232. ElDialog,
  233. ElTooltip,
  234. ElMessage,
  235. } from 'element-plus'
  236. import compEdit from './components/edit.vue'
  237. import compRecord from './components/record.vue'
  238. import { $t } from '@/i18n/index'
  239. import { getSupplierList, deleteSupplier } from '@/api/supplier.js'
  240. import userAPI from '@/api/user'
  241. defineComponent({
  242. name: 'ComponentIndentSupplierList',
  243. })
  244. const prefix = 'order.supplier.'
  245. let componentEditVisible = ref(0) // 1 新增, 2编辑. 0关闭
  246. let componentRecordVisible = ref(false) // 审核记录
  247. let dataForEdit = ref({}) // 修改时用, 只是用作传递给子组件数据的变量
  248. let recordId = ref('')
  249. let loading = ref(false)
  250. let categoryList = ref([
  251. '阿里巴巴平台付款',
  252. '70%定金',
  253. '50%定金',
  254. '40%定金',
  255. '30%定金',
  256. '全款',
  257. '月结',
  258. '半月结(两周结)',
  259. ])
  260. const currencyList = ref([
  261. 'AUD',
  262. 'NZD',
  263. 'CHY',
  264. 'GBP',
  265. 'EUR',
  266. 'USD',
  267. 'HKD',
  268. 'CAD',
  269. 'JPY',
  270. 'SGD',
  271. ])
  272. let form = ref({
  273. Vendor_Name: '',
  274. Payment_Terms: '',
  275. status: '',
  276. } as any)
  277. let total = ref(0)
  278. let pageForm = ref({
  279. page: 1,
  280. limit: 20,
  281. })
  282. let list = ref([])
  283. const mainTableConfig: any[] = [
  284. {
  285. label: 'order.supplier.label_Vendor_Name',
  286. field: 'Vendor_Name',
  287. },
  288. {
  289. label: 'order.supplier.label_Phone',
  290. field: 'Phone',
  291. width: '120',
  292. },
  293. {
  294. label: 'order.supplier.label_Payment_Terms',
  295. field: 'Payment_Terms',
  296. width: '110',
  297. },
  298. {
  299. label: '数据来源',
  300. field: 'fromwhere',
  301. width: '110',
  302. },
  303. {
  304. label: 'order.supplier.label_status',
  305. field: 'status',
  306. width: '110',
  307. style: 'font-weight: bold;',
  308. },
  309. {
  310. label: 'table_operator',
  311. field: 'admin_name',
  312. width: '90',
  313. },
  314. {
  315. label: 'table_operated_time',
  316. field: 'update_time',
  317. width: '180',
  318. },
  319. ]
  320. const statusList = [
  321. {
  322. value: 0,
  323. label: '待审核',
  324. },
  325. {
  326. value: 1,
  327. label: '审核通过',
  328. },
  329. {
  330. value: 2,
  331. label: '审核不通过',
  332. },
  333. ]
  334. const search = () => {
  335. pageForm.value = {
  336. page: 1,
  337. limit: 20,
  338. }
  339. getList()
  340. }
  341. const getStatusLabel = (value: number) => {
  342. const temp = statusList.filter((i: any) => i.value === value)
  343. return temp.length ? temp[0].label : '-'
  344. }
  345. const reset = () => {
  346. form.value = {
  347. Vendor_Name: '',
  348. Payment_Terms: '',
  349. status: '',
  350. }
  351. pageForm.value = {
  352. page: 1,
  353. limit: 20,
  354. }
  355. total.value = 0
  356. getList()
  357. }
  358. const edit = (row: any) => {
  359. dataForEdit.value = row
  360. componentEditVisible.value = 2
  361. }
  362. const deleteSupplierFunc = (row: any) => {
  363. ElMessageBox.confirm('将删除该供应商, 是否继续?', '提示', {
  364. confirmButtonText: '确定',
  365. cancelButtonText: '取消',
  366. type: 'warning',
  367. }).then(() => {
  368. deleteSupplier({ id: row.id }).then((res: any) => {
  369. if (res.code === 1) {
  370. getList()
  371. ElNotification({
  372. title: '删除成功',
  373. message: '正在刷新数据',
  374. duration: 3000,
  375. })
  376. }
  377. })
  378. })
  379. }
  380. const examine = (row: any) => {
  381. dataForEdit.value = row
  382. componentEditVisible.value = 3
  383. }
  384. const openRecord = (row: any) => {
  385. recordId.value = row.id
  386. componentRecordVisible.value = true
  387. }
  388. const getList = () => {
  389. const p: any = Object.assign({}, pageForm.value, form.value)
  390. loading.value = true
  391. getSupplierList(p)
  392. .then((res: any) => {
  393. list.value =
  394. res.result?.data?.map((main: any) => {
  395. let status = Number(main.status)
  396. if (typeof status !== 'number') status = 0
  397. return {
  398. ...main,
  399. status,
  400. }
  401. }) || []
  402. total.value = res.result.total
  403. })
  404. .finally(() => {
  405. loading.value = false
  406. })
  407. }
  408. getList()
  409. const currentBigImage = ref('')
  410. const bigImageVisible = ref(false)
  411. const imgClick = (url: string) => {
  412. currentBigImage.value = url
  413. bigImageVisible.value = true
  414. }
  415. watch(bigImageVisible, () => {
  416. if (!bigImageVisible.value) currentBigImage.value = ''
  417. })
  418. const userList = ref([] as any[])
  419. const getUserListFunc = () => {
  420. userAPI
  421. .getUserList({
  422. page: 1,
  423. limit: 200,
  424. })
  425. .then((res: any) => {
  426. if (res.code !== 1) {
  427. return
  428. }
  429. userList.value =
  430. res.result.data
  431. .filter((i: any) => i.status === 1)
  432. .sort((a: any, b: any) => a.name.localeCompare(b.name)) || []
  433. })
  434. }
  435. getUserListFunc()
  436. const auditUser = ref('')
  437. const getCurrentAuditUser = () => {
  438. userAPI.getAuditUser().then((res: any) => {
  439. console.log(res, 'res')
  440. if (
  441. res.code === 1 &&
  442. Array.isArray(res.result.data) &&
  443. res.result.data.length
  444. ) {
  445. const temp = res.result.data.filter((i: any) => i.type === 1)
  446. if (temp.length) auditUser.value = temp[0].check_id
  447. }
  448. })
  449. }
  450. getCurrentAuditUser()
  451. const setAuditUserLoading = ref(false)
  452. const setAuditUser = () => {
  453. setAuditUserLoading.value = true
  454. userAPI
  455. .setAuditUser({ check_id: auditUser.value, type: 1 })
  456. .then((res: any) => {
  457. console.log(res, 'res')
  458. if (res.code === 1) {
  459. ElMessage.success('设置成功')
  460. }
  461. })
  462. .finally(() => (setAuditUserLoading.value = false))
  463. }
  464. </script>
  465. <style lang="scss" scoped>
  466. .search-form {
  467. .el-input,
  468. .el-select,
  469. .el-date-editor {
  470. width: 220px;
  471. }
  472. }
  473. </style>