code.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <hc-body split>
  3. <template #left>
  4. <div class="hc-menu-contents-box">
  5. <el-scrollbar>
  6. <HcMenuSimple
  7. :datas="menuOptions"
  8. :keys="menuKey"
  9. :props="menuProps"
  10. @change="handleMenuValue"
  11. />
  12. </el-scrollbar>
  13. </div>
  14. </template>
  15. <hc-card>
  16. <template #header>
  17. <span class="text-orange">*编号更改后,所有已生成的资料删除编号内容,保存后重新自动生成。</span>
  18. </template>
  19. <template #extra>
  20. <HcTooltip keys="tentative-basic-code-add">
  21. <el-button
  22. hc-btn
  23. type="primary"
  24. @click="handleAdd()"
  25. >
  26. <HcIcon name="add-circle" />
  27. <span>新增</span>
  28. </el-button>
  29. </HcTooltip>
  30. <HcTooltip keys="tentative-basic-code-sort">
  31. <el-button hc-btn type="primary" color="#12C060" style="color: white;">
  32. <HcIcon name="arrow-up-down" />
  33. <span>排序</span>
  34. </el-button>
  35. </HcTooltip>
  36. <HcTooltip keys="tentative-basic-code-resign">
  37. <el-button
  38. hc-btn
  39. color="#e03997" style="color: white;"
  40. :loading="resetLoad"
  41. @click="resetModalClick"
  42. >
  43. <HcIcon name="restart" />
  44. <span>重置编号</span>
  45. </el-button>
  46. </HcTooltip>
  47. <HcTooltip keys="tentative-basic-code-delete">
  48. <el-button hc-btn color="red" :loading="delModalLoad" @click="delModalClick">
  49. <HcIcon name="delete-bin-2" />
  50. <span>删除</span>
  51. </el-button>
  52. </HcTooltip>
  53. </template>
  54. <HcTable
  55. ref="tableRef" :column="tableColumn" :datas="tableData" :loading="tableLoad"
  56. is-new :index-style="{ width: 60 }" is-check :check-style="{ width: 29 }"
  57. @selection-change="tableSelection"
  58. >
  59. <template #type="{ row }">
  60. <el-select v-if="row.isEdit" v-model="row.type" placeholder="请选择">
  61. <el-option
  62. v-for="item in typeOptions"
  63. :key="item.key"
  64. :label="item.label"
  65. :value="item.key"
  66. />
  67. </el-select>
  68. <span v-else>{{ getTypeLabel(row.type) }}</span>
  69. </template>
  70. <template #data="{ row }">
  71. <el-input v-if="row.isEdit" v-model="row.data" placeholder="请输入数据" />
  72. <span v-else>{{ row.data }}</span>
  73. </template>
  74. <template #isAutoIncrement="{ row }">
  75. <el-checkbox v-if="row?.type === '6'" v-model="row.isAutoIncrement" :disabled="!row.isEdit">是否自增</el-checkbox>
  76. </template>
  77. <template #action="{ row }">
  78. <el-button
  79. v-if="!row.isEdit"
  80. type="primary"
  81. link
  82. @click="handleEdit(row)"
  83. >
  84. <HcIcon name="edit-2" />
  85. 编辑
  86. </el-button>
  87. <el-button
  88. v-if="row.isEdit"
  89. type="success"
  90. link
  91. :loading="row.saveLoading"
  92. @click="handleSave(row)"
  93. >
  94. <HcIcon name="save-3" />
  95. 保存
  96. </el-button>
  97. <el-button
  98. v-del-com:[handleDelete]="row"
  99. type="danger"
  100. link
  101. >
  102. <HcIcon name="delete-bin-2" />
  103. 删除
  104. </el-button>
  105. </template>
  106. </HcTable>
  107. </hc-card>
  108. </hc-body>
  109. </template>
  110. <script setup>
  111. import { onMounted, ref } from 'vue'
  112. import { getDictionary } from '~api/other'
  113. import { arrToId, getArrValue } from 'js-fast-way'
  114. import dataApi from '~api/basic/code'
  115. import { useAppStore } from '~src/store'
  116. import { HcDelMsg } from 'hc-vue3-ui'
  117. const store = useAppStore()
  118. const projectId = ref(store.getProjectId)
  119. const contractId = ref(store.getContractId)
  120. onMounted(()=>{
  121. getTypeOptions()
  122. getTableData()
  123. })
  124. //左侧菜单
  125. const menuKey = ref('1')
  126. const menuOptions = ref([
  127. { key: '1', label: '材料编号' },
  128. { key: '2', label: '样品编号' },
  129. { key: '3', label: '委托单编号' },
  130. { key: '4', label: '记录表编号' },
  131. { key: '5', label: '报告表编号' },
  132. ])
  133. //左侧菜单
  134. const menuProps = {
  135. key: 'key',
  136. label: 'label',
  137. }
  138. const typeOptions = ref([])
  139. const getTypeOptions = async ()=>{
  140. const { data } = await getDictionary({
  141. code: 'trial_number_rule',
  142. })
  143. //处理数据
  144. let newArr = []
  145. const newData = getArrValue(data)
  146. for (let i = 0; i < newData.length; i++) {
  147. newArr.push({
  148. label: newData[i]['dictValue'],
  149. key: newData[i]['dictKey'],
  150. })
  151. }
  152. typeOptions.value = newArr
  153. }
  154. // 查找typeOptions中对应的label
  155. const getTypeLabel = (typeKey) => {
  156. return typeOptions.value.find(item => item.key === typeKey)?.label || '未知类型'
  157. }
  158. const handleMenuValue = (item) => {
  159. menuKey.value = item.key
  160. getTableData()
  161. }
  162. //获取数据
  163. const tableLoad = ref(true)
  164. const tableData = ref([])
  165. const tableRef = ref(null)
  166. const tableColumn = ref([
  167. { key: 'type', name: '规则' },
  168. { key: 'data', name: '数据填充' },
  169. { key: 'isAutoIncrement', name: '是否自增' },
  170. { key: 'action', name: '操作' },
  171. ])
  172. const getTableData = async () => {
  173. tableLoad.value = true
  174. const { error, code, data } = await dataApi.getTrialNumberRule({
  175. projectId: projectId.value,
  176. contractId: contractId.value,
  177. type: menuKey.value,
  178. })
  179. //处理数据
  180. tableLoad.value = false
  181. if (!error && code === 200) {
  182. tableData.value = getArrValue(data['records'])
  183. } else {
  184. tableData.value = []
  185. }
  186. }
  187. //多选
  188. const tableCheckedKeys = ref([])
  189. const tableSelection = (rows) => {
  190. tableCheckedKeys.value = rows
  191. }
  192. // 编辑行
  193. const handleEdit = (row) => {
  194. row.isEdit = true
  195. }
  196. const saveLoading = ref(false)
  197. // 保存行
  198. const handleSave = async (row) => {
  199. saveLoading.value = true
  200. const { error, code, msg } = await dataApi.save({
  201. ...row,
  202. projectId: projectId.value,
  203. contractId: contractId.value,
  204. })
  205. //处理数据
  206. saveLoading.value = false
  207. if (!error && code === 200) {
  208. window?.$message?.success(msg)
  209. row.isEdit = false
  210. getTableData()
  211. }
  212. }
  213. const handleDelete = async ({ item }, resolve) => {
  214. await delData(item.id)
  215. resolve()
  216. }
  217. //删除请求
  218. const delData = async (id) => {
  219. const { error, code, msg } = await dataApi.delData({
  220. contractId: contractId.value,
  221. pkeyId: id,
  222. }, false)
  223. //判断状态
  224. if (!error && code === 200) {
  225. window?.$message?.success(msg)
  226. getTableData()
  227. } else {
  228. window?.$message?.error(msg)
  229. }
  230. }
  231. //删除节点
  232. const delModalLoad = ref(false)
  233. const delModalClick = () => {
  234. delModalLoad.value = true
  235. const rows = tableCheckedKeys.value
  236. const ids = arrToId(rows)
  237. HcDelMsg(async (resolve) => {
  238. await delData(ids)
  239. delModalLoad.value = false
  240. resolve() //关闭弹窗的回调
  241. })
  242. }
  243. const handleAdd = () => {
  244. tableData.value.push({
  245. isEdit: true,
  246. })
  247. }
  248. const resetLoad = ref(false)
  249. const resetModalClick = async () => {
  250. // getTableData()
  251. resetLoad.value = true
  252. const { error, code, data, msg } = await dataApi.reTrialNumberRule({
  253. projectId: projectId.value,
  254. contractId: contractId.value,
  255. type: menuKey.value,
  256. })
  257. //处理数据
  258. resetLoad.value = false
  259. if (!error && code === 200) {
  260. window?.$message?.success(msg)
  261. getTableData()
  262. }
  263. }
  264. </script>