index.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. <template>
  2. <div class="supervision-content-container content-container">
  3. <div v-if="activeView === 'list'">
  4. <!-- 搜索表单 -->
  5. <div class="search-panel">
  6. <el-form :inline="true" :model="searchForm" class="search-form">
  7. <el-form-item label="监审类别:">
  8. <el-cascader
  9. v-model="searchForm.catalogId"
  10. :options="catalogListOptions"
  11. v-bind="props"
  12. style="width: 100%"
  13. clearable
  14. ></el-cascader>
  15. </el-form-item>
  16. <el-form-item label="状态:">
  17. <el-select
  18. v-model="searchForm.status"
  19. placeholder="请选择状态"
  20. clearable
  21. >
  22. <el-option
  23. v-for="item in statusOptions"
  24. :key="item.value"
  25. :label="item.label"
  26. :value="item.value"
  27. ></el-option>
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item>
  31. <el-button
  32. type="primary"
  33. icon="el-icon-search"
  34. @click="handleSearch"
  35. >
  36. 搜索
  37. </el-button>
  38. <el-button
  39. plain
  40. type="primary"
  41. icon="el-icon-refresh"
  42. @click="handleReset"
  43. >
  44. 重置
  45. </el-button>
  46. </el-form-item>
  47. </el-form>
  48. </div>
  49. <!-- 操作按钮 -->
  50. <div class="operation-bar">
  51. <!-- v-region-permission="{ category: 'costFormManage', action: 'add' }" -->
  52. <el-button
  53. plain
  54. type="success"
  55. icon="el-icon-circle-plus"
  56. @click="handleAdd"
  57. >
  58. 添加
  59. </el-button>
  60. <!-- v-region-permission="{ category: 'costFormManage', action: 'delete' }" -->
  61. <el-button
  62. plain
  63. type="danger"
  64. icon="el-icon-delete"
  65. :disabled="selectedRows.length === 0"
  66. @click="handleBatchDelete"
  67. >
  68. 删除
  69. </el-button>
  70. </div>
  71. <!-- 表格 -->
  72. <div class="table-container">
  73. <CostAuditTable
  74. ref="costAuditTable"
  75. :table-data="tableData"
  76. :columns="tableColumns"
  77. :show-selection="true"
  78. :show-index="true"
  79. :show-pagination="true"
  80. :pagination="pagination"
  81. :loading="loading"
  82. :table-props="{
  83. defaultSort: { prop: 'createTime', order: 'descending' },
  84. }"
  85. @selection-change="handleSelectionChange"
  86. @pagination-change="handlePaginationChange"
  87. >
  88. <!-- :table-props="{
  89. defaultSort: { prop: 'createTime', order: 'descending' },
  90. }" -->
  91. <template #catalogId="{ row }">
  92. <span class="table-name-link">
  93. {{ getCatalogNames(row) }}
  94. </span>
  95. </template>
  96. <!-- 调查表名称自定义单元格 -->
  97. <template #surveyTemplateName="{ row }">
  98. <span class="table-name-link" @click="handleViewDetail(row)">
  99. {{ row.surveyTemplateName }}
  100. </span>
  101. </template>
  102. <!-- 创建时间自定义单元格 -->
  103. <template #createTime="{ row }">
  104. <div>{{ row.createTime ? row.createTime.split(' ')[0] : '-' }}</div>
  105. <div>{{ row.createTime ? row.createTime.split(' ')[1] : '-' }}</div>
  106. </template>
  107. <!-- 操作列 -->
  108. <template #action="{ row }">
  109. <!-- v-region-permission="{
  110. category: 'costFormManage',
  111. action: 'view',
  112. }" -->
  113. <el-button type="text" size="mini" @click="handleViewDetail(row)">
  114. 详情
  115. </el-button>
  116. <!-- 查看内容详情 -->
  117. <!-- <el-button
  118. v-if="!$permission.isAdminOrProvince()"
  119. type="text"
  120. size="mini"
  121. @click="handleDropdownCommand('infoMaintain', row)"
  122. >
  123. 内容详情
  124. </el-button> -->
  125. <!-- v-region-permission="{
  126. category: 'costFormManage',
  127. action: 'edit',
  128. targetData: row,
  129. }" -->
  130. <el-button type="text" size="mini" @click="handleEdit(row)">
  131. 修改
  132. </el-button>
  133. <!-- v-region-permission="{
  134. category: 'costFormManage',
  135. action: 'delete',
  136. targetData: row,
  137. }" -->
  138. <el-button
  139. class="delete-btn"
  140. type="text"
  141. size="mini"
  142. @click="handleDelete(row)"
  143. >
  144. 删除
  145. </el-button>
  146. <!-- v-region-permission="{
  147. category: 'costFormManage',
  148. action: 'edit',
  149. targetData: row,
  150. }" -->
  151. <el-dropdown class="ml10" trigger="click">
  152. <el-button type="text" size="mini">
  153. 更多
  154. <i class="el-icon-arrow-down el-icon--right"></i>
  155. </el-button>
  156. <el-dropdown-menu slot="dropdown">
  157. <!-- v-region-permission="{
  158. category: 'costFormManage',
  159. action: 'edit',
  160. targetData: row,
  161. }" -->
  162. <el-dropdown-item
  163. @click.native="handleDropdownCommand('infoMaintain', row)"
  164. >
  165. 内容维护
  166. </el-dropdown-item>
  167. <!-- v-region-permission="{
  168. category: 'costFormManage',
  169. action: 'edit',
  170. targetData: row,
  171. }" -->
  172. <el-dropdown-item
  173. @click.native="handleDropdownCommand('status', row)"
  174. >
  175. {{ row.status === '0' ? '停用' : '启用' }}
  176. </el-dropdown-item>
  177. </el-dropdown-menu>
  178. </el-dropdown>
  179. </template>
  180. </CostAuditTable>
  181. </div>
  182. </div>
  183. <div v-if="activeView === 'infoMaintain'">
  184. <InfoMaintain
  185. ref="infoMaintain"
  186. @back="activeView = $event"
  187. ></InfoMaintain>
  188. </div>
  189. <!-- 添加/修改弹窗 -->
  190. <CostAuditDialog
  191. :title="dialogTitle"
  192. :visible.sync="dialogVisible"
  193. width="650px"
  194. :close-on-click-modal="false"
  195. :show-confirm-btn="dialogTitle !== '查看成本调查表'"
  196. :cancel-text="dialogTitle === '查看成本调查表' ? '关 闭' : '取 消'"
  197. :confirm-loading="submitLoading"
  198. @confirm="submitForm"
  199. @cancel="handleDialogCancel"
  200. @close="handleDialogClose"
  201. >
  202. <CostAuditForm
  203. ref="dataForm"
  204. form-type="dialog"
  205. :form-data="formData"
  206. :form-items="dialogFormItems"
  207. :rules="rules"
  208. :show-action-buttons="false"
  209. :label-width="'160px'"
  210. :form-props="{ disabled: dialogTitle === '查看成本调查表' }"
  211. @update:form-data="(val) => (formData = val)"
  212. >
  213. <template #catalogId>
  214. <el-cascader
  215. v-model="formData.catalogId"
  216. :options="catalogListOptions"
  217. v-bind="props"
  218. style="width: 100%"
  219. @change="handleCatalogChange"
  220. ></el-cascader>
  221. </template>
  222. <template #surveyTemplateName>
  223. <el-input
  224. v-model="formData.surveyTemplateName"
  225. v-pinyin-abbreviation="{
  226. target: 'formData.surveyTemplateNameYw',
  227. }"
  228. placeholder="请输入调查表名称"
  229. />
  230. </template>
  231. <template #surveyTemplateNameYw>
  232. <el-input
  233. v-model="formData.surveyTemplateNameYw"
  234. placeholder="请输入调查表英文名称"
  235. />
  236. </template>
  237. <template #templateType>
  238. <el-radio v-model="formData.templateType" label="1">单记录</el-radio>
  239. <el-radio v-model="formData.templateType" label="2">固定表</el-radio>
  240. <el-radio v-model="formData.templateType" label="3">动态表</el-radio>
  241. </template>
  242. <!-- <template #storageTable>
  243. <el-input
  244. v-model="formData.storageTable"
  245. placeholder="请输入调查表数据存储库表"
  246. />
  247. </template> -->
  248. <template #remarks>
  249. <el-input v-model="formData.remarks" type="textarea"
  250. placeholder="请输入说明,填写调查表的业务说明、填报指引等内容" type:
  251. rows='4' maxlength="200" />
  252. </template>
  253. </CostAuditForm>
  254. </CostAuditDialog>
  255. </div>
  256. </template>
  257. <script>
  258. import {
  259. getCostFormList,
  260. addCostForm,
  261. editCostForm,
  262. deleteCostForm,
  263. changeCostFormStatus,
  264. getCostFormDetail,
  265. getstorageTableOptions,
  266. } from '@/api/costFormManage'
  267. import CostAuditTable from '@/components/costAudit/CostAuditTable.vue'
  268. import CostAuditForm from '@/components/costAudit/CostAuditForm.vue'
  269. import CostAuditDialog from '@/components/costAudit/CostAuditDialog.vue'
  270. import {
  271. getSurveyTemplate,
  272. addSurveyTemplate,
  273. delSurveyTemplateById,
  274. delSurveyTemplates,
  275. } from '@/api/costSurveyTemplate'
  276. import { getCatalogDetail } from '@/api/catalogManage'
  277. import InfoMaintain from './infoMaintain.vue'
  278. import { catalogMixin, commonMixin } from '@/mixins/useDict'
  279. export default {
  280. name: 'CostFormManage',
  281. components: {
  282. CostAuditTable,
  283. CostAuditForm,
  284. CostAuditDialog,
  285. InfoMaintain,
  286. },
  287. // 使用混入
  288. mixins: [catalogMixin, commonMixin],
  289. data() {
  290. return {
  291. activeView: 'list',
  292. // 搜索表单
  293. searchForm: {
  294. catalogId: '',
  295. contentType: '',
  296. status: '',
  297. },
  298. // 表格数据
  299. tableData: [],
  300. // 分页信息
  301. pagination: {
  302. currentPage: 1,
  303. pageSize: 50,
  304. total: 0,
  305. },
  306. // 加载状态
  307. loading: false,
  308. submitLoading: false,
  309. // 选中行
  310. selectedRows: [],
  311. // 弹窗相关
  312. dialogVisible: false,
  313. dialogTitle: '',
  314. isEdit: false,
  315. formData: {
  316. catalogId: '',
  317. contentType: '',
  318. surveyTemplateName: '',
  319. surveyTemplateNameYw: '',
  320. templateType: '1',
  321. storageTable: '',
  322. remarks: '',
  323. },
  324. CatalogNameMap: {},
  325. currentRow: null,
  326. // 表单验证规则
  327. rules: {
  328. catalogId: [
  329. { required: true, message: '请选择监审类别', trigger: 'change' },
  330. ],
  331. surveyTemplateName: [
  332. { required: true, message: '请输入调查表名称', trigger: 'blur' },
  333. { max: 50, message: '长度不能超过50个字符', trigger: 'blur' },
  334. ],
  335. surveyTemplateNameYw: [
  336. {
  337. required: true,
  338. message: '请输入调查表英文名称',
  339. trigger: 'blur',
  340. },
  341. { max: 30, message: '长度不能超过30个字符', trigger: 'blur' },
  342. {
  343. pattern: /^[a-zA-Z0-9_]+$/,
  344. message: '请输入字母或数字或下划线',
  345. trigger: 'blur',
  346. },
  347. ],
  348. storageTable: [
  349. {
  350. required: true,
  351. message: '请选择数据存储表名称',
  352. trigger: 'change',
  353. },
  354. ],
  355. },
  356. // -1草稿,0启用,1停用
  357. statusOptions: [
  358. { value: '-1', label: '草稿' },
  359. { value: '0', label: '启用' },
  360. { value: '1', label: '停用' },
  361. ],
  362. props: {
  363. filterable: true,
  364. placeholder: '请选择监审类别',
  365. style: 'width: 100%',
  366. showAllLevels: false,
  367. props: {
  368. multiple: false,
  369. children: 'children',
  370. checkStrictly: false,
  371. label: 'catalogName',
  372. value: 'id',
  373. emitPath: false,
  374. },
  375. },
  376. }
  377. },
  378. computed: {
  379. // 对话框表单项配置
  380. dialogFormItems() {
  381. return [
  382. {
  383. prop: 'catalogId',
  384. label: '监审类别:',
  385. type: 'cascader',
  386. slotName: 'catalogId',
  387. props: {
  388. placeholder: '请选择监审类别',
  389. style: { width: '100%' },
  390. checkStrictly: false,
  391. },
  392. options: this.catalogIdOptions,
  393. },
  394. {
  395. prop: 'surveyTemplateName',
  396. label: '调查表名称:',
  397. type: 'input',
  398. props: {
  399. placeholder: '请输入调查表名称',
  400. },
  401. slotName: 'surveyTemplateName',
  402. },
  403. {
  404. prop: 'surveyTemplateNameYw',
  405. label: '调查表英文名称:',
  406. type: 'input',
  407. props: {
  408. placeholder: '请输入调查表英文名称',
  409. },
  410. slotName: 'surveyTemplateNameYw',
  411. },
  412. {
  413. prop: 'templateType',
  414. label: '表单样式:',
  415. slotName: 'templateType',
  416. },
  417. // {
  418. // prop: 'storageTable',
  419. // label: '调查表数据存储库表:',
  420. // type: 'input',
  421. // slotName: 'storageTable',
  422. // },
  423. {
  424. prop: 'remarks',
  425. label: '说明:',
  426. type: 'input',
  427. slotName: 'remarks',
  428. props: {
  429. type: 'textarea',
  430. rows: 4,
  431. maxlength: 200,
  432. placeholder: '请输入说明,填写调查表的业务说明、填报指引等内容',
  433. },
  434. },
  435. ]
  436. },
  437. // 表格列配置
  438. tableColumns() {
  439. return [
  440. {
  441. prop: 'catalogId',
  442. label: '监审类别',
  443. slotName: 'catalogId',
  444. },
  445. {
  446. prop: 'surveyTemplateName',
  447. label: '调查表名称',
  448. slotName: 'surveyTemplateName',
  449. },
  450. {
  451. prop: 'templateType',
  452. label: '模版类型',
  453. width: '100px',
  454. formatter: (row) => {
  455. return row.templateType == '1'
  456. ? '单记录'
  457. : row.templateType == '2'
  458. ? '固定表'
  459. : '动态表'
  460. },
  461. },
  462. // {
  463. // prop: 'storageTable',
  464. // label: '调查表数据存储表',
  465. // },
  466. {
  467. prop: 'status',
  468. label: '状态',
  469. width: '100px',
  470. formatter: (row) => {
  471. return row.status == '-1'
  472. ? '草稿'
  473. : row.status == '0'
  474. ? '启用'
  475. : '停用'
  476. },
  477. },
  478. {
  479. prop: 'createTime',
  480. label: '创建时间',
  481. slotName: 'createTime',
  482. width: '120px',
  483. sortable: true,
  484. },
  485. {
  486. prop: 'action',
  487. label: '操作',
  488. width: 240,
  489. align: 'center',
  490. fixed: 'right',
  491. slotName: 'action',
  492. },
  493. ]
  494. },
  495. },
  496. watch: {
  497. // 监听目录数据变化,数据加载完成后处理回显
  498. catalogListOptions: {
  499. handler(newVal) {
  500. if (newVal && newVal.length > 0) {
  501. // 数据加载完成后,重新处理value
  502. this.batchGetCatalogNames()
  503. }
  504. },
  505. immediate: true,
  506. },
  507. },
  508. mounted() {
  509. // 初始化表单选项
  510. // this.initFormOptions()
  511. // 初始加载数据
  512. this.handleSearch()
  513. },
  514. methods: {
  515. handleCatalogChange(val) {
  516. // 设置表单数据
  517. this.$set(this.formData, 'catalogId', val)
  518. console.log(this.formData.catalogId)
  519. this.$nextTick(() => {
  520. if (this.$refs.dataForm && this.$refs.dataForm.$refs.formRef) {
  521. this.$refs.dataForm.$refs.formRef.clearValidate('catalogId')
  522. }
  523. })
  524. },
  525. // 初始化表单选项
  526. initFormOptions() {
  527. // 将选项数据同步到表单配置中
  528. this.searchFormItems[0].options = this.catalogIdOptions
  529. this.searchFormItems[1].options = this.contentTypeOptions
  530. this.searchFormItems[2].options = this.statusOptions
  531. this.dialogFormItems[0].options = this.catalogIdOptions
  532. this.dialogFormItems[1].options = this.contentTypeOptions
  533. this.dialogFormItems[4].options = this.storageTableOptions
  534. },
  535. // 搜索
  536. handleSearch() {
  537. this.loading = true
  538. const params = {
  539. catalogId: this.searchForm.catalogId,
  540. status: this.searchForm.status,
  541. contentType: '',
  542. type: '',
  543. keyword: '',
  544. page: this.pagination.currentPage,
  545. pageSize: this.pagination.pageSize,
  546. }
  547. getCostFormList(params)
  548. .then((res) => {
  549. if (res.rows.length > 0) {
  550. this.tableData = res.rows || []
  551. this.pagination.total = res.total || 0
  552. }
  553. })
  554. .catch((error) => {
  555. console.error('搜索失败:', error)
  556. })
  557. .finally(() => {
  558. this.loading = false
  559. })
  560. },
  561. // 重置
  562. handleReset() {
  563. this.searchForm = {
  564. catalogId: '',
  565. contentType: '',
  566. status: '',
  567. }
  568. this.pagination.currentPage = 1
  569. this.handleSearch()
  570. },
  571. // 添加
  572. handleAdd() {
  573. this.getstorageTableOpt()
  574. this.dialogTitle = '添加成本调查表'
  575. this.isEdit = false
  576. this.formData = {
  577. catalogId: '',
  578. contentType: '',
  579. surveyTemplateName: '',
  580. surveyTemplateNameYw: '',
  581. templateType: '1',
  582. storageTable: '',
  583. remarks: '',
  584. }
  585. this.dialogVisible = true
  586. },
  587. getstorageTableOpt() {
  588. // getstorageTableOptions().then((res) => {
  589. // this.storageTableOptions = res.value
  590. // this.dialogFormItems[4].options = res.value
  591. // })
  592. },
  593. getCatalogNames(row) {
  594. if (!row.catalogId) return ''
  595. return row.catalogId
  596. .split(',')
  597. .map((id) => {
  598. const trimId = id.trim()
  599. return this.CatalogNameMap[trimId] || '未知名称'
  600. })
  601. .join(',')
  602. },
  603. // 获取监审类别名称
  604. batchGetCatalogNames() {
  605. // 递归查找名称
  606. this.CatalogNameMap = {}
  607. this._recursiveCatalogMap(this.catalogListOptions)
  608. },
  609. // 递归遍历目录树并构建ID到名称的映射
  610. _recursiveCatalogMap(catalogs) {
  611. if (!Array.isArray(catalogs) || catalogs.length === 0) {
  612. return
  613. }
  614. catalogs.forEach((item) => {
  615. // 为当前目录项添加映射
  616. this.CatalogNameMap[item.id] = item.catalogName
  617. // 递归处理子目录
  618. if (item.children && Array.isArray(item.children)) {
  619. this._recursiveCatalogMap(item.children)
  620. }
  621. })
  622. },
  623. // 批量删除
  624. handleBatchDelete() {
  625. if (this.selectedRows.length === 0) {
  626. this.$message.warning('请先选择要删除的数据')
  627. return
  628. }
  629. this.$confirm(
  630. `确定要删除选中的 ${this.selectedRows.length} 条数据吗?`,
  631. '删除确认',
  632. {
  633. confirmButtonText: '确定',
  634. cancelButtonText: '取消',
  635. type: 'warning',
  636. }
  637. ).then(() => {
  638. const ids = this.selectedRows.map((row) => row.surveyTemplateId)
  639. this.loading = true
  640. delSurveyTemplates(ids)
  641. .then((res) => {
  642. if (res.code === 200) {
  643. this.$message.success('批量删除成功')
  644. this.selectedRows = []
  645. this.handleSearch()
  646. }
  647. })
  648. .catch((error) => {
  649. console.error('批量删除失败:', error)
  650. })
  651. .finally(() => {
  652. this.loading = false
  653. })
  654. })
  655. },
  656. // 表格选择变化
  657. handleSelectionChange(selection) {
  658. this.selectedRows = selection
  659. },
  660. // 查看详情
  661. handleViewDetail(row) {
  662. // 处理级联选择器多选回显数据
  663. // const result = this.formatRelatedItemsForDisplay({
  664. // catalogId: {
  665. // value: row.catalogId,
  666. // options: this.catalogListOptions,
  667. // id: 'id',
  668. // parentId: 'parentId',
  669. // },
  670. // })
  671. this.dialogVisible = true
  672. this.dialogTitle = `查看成本调查表`
  673. this.formData = {
  674. ...row,
  675. // catalogId: result.catalogId ? result.catalogId : [],
  676. }
  677. },
  678. // 修改
  679. handleEdit(row) {
  680. // 处理级联选择器多选回显数据
  681. // const result = this.formatRelatedItemsForDisplay({
  682. // catalogId: {
  683. // value: row.catalogId,
  684. // options: this.catalogListOptions,
  685. // id: 'id',
  686. // parentId: 'parentId',
  687. // },
  688. // })
  689. this.dialogTitle = '修改成本调查表'
  690. this.isEdit = true
  691. this.formData = {
  692. ...row,
  693. // catalogId: result.catalogId ? result.catalogId : [],
  694. }
  695. this.dialogVisible = true
  696. },
  697. // 删除
  698. handleDelete(row) {
  699. this.$confirm(
  700. `确定要删除 "${row.surveyTemplateName}" 吗?`,
  701. '删除确认',
  702. {
  703. confirmButtonText: '确定',
  704. cancelButtonText: '取消',
  705. type: 'warning',
  706. }
  707. ).then(() => {
  708. this.loading = true
  709. delSurveyTemplateById({ id: row.surveyTemplateId })
  710. .then((res) => {
  711. if (res.code === 200) {
  712. this.$message.success('删除成功')
  713. this.handleSearch()
  714. }
  715. })
  716. .catch((error) => {
  717. console.error('删除失败:', error)
  718. })
  719. .finally(() => {
  720. this.loading = false
  721. })
  722. })
  723. },
  724. // 下拉菜单命令处理
  725. handleDropdownCommand(command, row) {
  726. // infoMaintain
  727. switch (command) {
  728. case 'infoMaintain':
  729. // this.currentRow = row
  730. this.activeView = 'infoMaintain'
  731. this.$nextTick(() => {
  732. this.$refs.infoMaintain.getTemplateRow(row)
  733. })
  734. break
  735. case 'status':
  736. this.handleStatus(row)
  737. break
  738. default:
  739. break
  740. }
  741. },
  742. // 启动/停用状态
  743. handleStatus(row) {
  744. const action = row.status == '0' ? '停用' : '启用'
  745. this.$confirm(`确认要${action}该数据吗?`, '操作确认', {
  746. confirmButtonText: '确定',
  747. cancelButtonText: '取消',
  748. type: 'warning',
  749. })
  750. .then(() => {
  751. changeCostFormStatus(row.surveyTemplateId)
  752. .then((res) => {
  753. if (res.code === 200) {
  754. this.$message.success(res.message || `${action}成功`)
  755. this.handleSearch()
  756. }
  757. })
  758. .catch(() => {})
  759. })
  760. .catch(() => {
  761. this.$message({
  762. type: 'info',
  763. message: '已取消操作',
  764. })
  765. })
  766. },
  767. // 分页变化处理
  768. handlePaginationChange({ currentPage, pageSize }) {
  769. this.pagination.currentPage = currentPage
  770. this.pagination.pageSize = pageSize
  771. this.handleSearch()
  772. },
  773. // 弹窗关闭处理
  774. handleDialogClose() {
  775. // 重置表单验证状态
  776. if (this.$refs.dataForm) {
  777. this.$refs.dataForm.$refs.formRef.resetFields()
  778. }
  779. },
  780. // 弹窗取消处理
  781. handleDialogCancel() {
  782. this.dialogVisible = false
  783. },
  784. // 提交表单
  785. submitForm() {
  786. if (this.dialogTitle === '查看成本调查表') {
  787. return
  788. }
  789. // 处理级联选择器多选数据
  790. // const resultData = this.extractLastLevelValues({
  791. // catalogId: this.formData.catalogId,
  792. // })
  793. const data = {
  794. ...this.formData,
  795. // ...resultData,
  796. }
  797. this.$refs.dataForm
  798. .validate()
  799. .then(() => {
  800. this.submitLoading = true
  801. if (this.isEdit) {
  802. // 修改
  803. editCostForm(data)
  804. .then((res) => {
  805. if (res.code === 200) {
  806. this.$message.success('修改成功')
  807. this.dialogVisible = false
  808. this.handleSearch()
  809. }
  810. })
  811. .catch((error) => {
  812. console.error('修改失败:', error)
  813. })
  814. .finally(() => {
  815. this.submitLoading = false
  816. })
  817. } else {
  818. addSurveyTemplate(data)
  819. .then((res) => {
  820. if (res.code === 200) {
  821. this.$message.success('添加成功')
  822. this.dialogVisible = false
  823. this.handleSearch()
  824. }
  825. })
  826. .catch((error) => {
  827. console.error('添加失败:', error)
  828. })
  829. .finally(() => {
  830. this.submitLoading = false
  831. })
  832. }
  833. })
  834. .catch((error) => {
  835. console.error('表单验证失败:', error)
  836. })
  837. },
  838. },
  839. }
  840. </script>
  841. <style scoped lang="scss">
  842. @import '@/styles/costAudit.scss';
  843. </style>