阅行客电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

375 lines
13 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <!--批量修改-->
  3. <el-dialog class="fileUpload-dialog" title="批量修改" :close-on-click-modal="false" :modal-append-to-body="false" append-to-body :visible.sync="bulkEditingVisible" :before-close="handleCloseDialog">
  4. <div class="setting-dialog">
  5. <div class="bulk-editing-container">
  6. <el-form ref="editForm" :model="editForm" :rules="editRules" label-width="100px">
  7. <el-form-item label="修改字段" prop="updateField">
  8. <el-select v-model="editForm.updateField" value-key="id" placeholder="请选择" style="width: 360px;" @change="selectField">
  9. <el-option
  10. v-for="item in fieldItemOptions"
  11. :key="item.id"
  12. :label="item.fieldCnName"
  13. :value="item"
  14. />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="修改方式" prop="updateType">
  18. <el-select v-model="editForm.updateType" placeholder="请选择" style="width: 360px;">
  19. <el-option
  20. v-for="item in editTypeOptions"
  21. :key="item.value"
  22. :label="item.label"
  23. :value="item.value"
  24. />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item v-if="editForm.updateType === 2" label="查询内容" prop="oldContext">
  28. <el-input v-model="editForm.oldContext" style="width: 360px;" />
  29. </el-form-item>
  30. <el-form-item label="更新内容" prop="updateContext">
  31. <!-- <el-select v-if="editForm.updateField.mateData === 3" v-model="editForm.updateContext" placeholder="请选择" style="width: 360px;">
  32. <el-option
  33. v-for="item in dictionaryOptions"
  34. :key="item.dictionaryId"
  35. :label="item.dictionaryName"
  36. :value="item.dictionaryName"
  37. />
  38. </el-select> -->
  39. <treeselect
  40. v-if="editForm.updateField.mateData === 3"
  41. v-model="editForm.updateContext"
  42. :options="dictionaryOptions"
  43. style="width: 360px;"
  44. flat
  45. :multiple="false"
  46. :normalizer="normalizerProject"
  47. placeholder="请选择"
  48. ><div slot="value-label" slot-scope="{ node }">{{ getAutoNameUnknown(node.label) }}</div></treeselect>
  49. <el-select v-else-if="editForm.updateField.mateData === 1" v-model="editForm.updateContext" placeholder="请选择" style="width: 360px;">
  50. <el-option
  51. v-for="item in fondsOptions"
  52. :key="item.fondsNo"
  53. :label="item.fondsName"
  54. :value="item.fondsNo"
  55. />
  56. </el-select>
  57. <treeselect
  58. v-else-if="editForm.updateField.mateData === 2"
  59. v-model="editForm.updateContext"
  60. :options="classifyOptions"
  61. style="width: 360px;"
  62. flat
  63. :multiple="false"
  64. :normalizer="normalizer"
  65. placeholder="请选择"
  66. ><div slot="value-label" slot-scope="{ node }">{{ getAutoNameUnknown(node.label) }}</div></treeselect>
  67. <el-date-picker
  68. v-else-if="editForm.updateField.isInputClass === 'date'"
  69. v-model="editForm.updateContext"
  70. type="date"
  71. placeholder="选择日期"
  72. style="width: 360px;"
  73. />
  74. <el-input-number
  75. v-else-if="editForm.updateField.isInputClass === 'number'"
  76. v-model.number="editForm.initialValue"
  77. :min="0"
  78. :max="999"
  79. controls-position="right"
  80. style="width: 360px;"
  81. />
  82. <el-input v-else v-model="editForm.updateContext" style="width: 360px;" />
  83. </el-form-item>
  84. </el-form>
  85. </div>
  86. <div slot="footer" class="dialog-footer">
  87. <el-button type="text" @click="handleCloseDialog">取消</el-button>
  88. <el-button type="primary" @click.native="onSubmitBlukEditing('editForm')">确定</el-button>
  89. </div>
  90. </div>
  91. </el-dialog>
  92. </template>
  93. <script>
  94. import { FetchInitCategoryInputFieldByPid } from '@/api/system/category/category'
  95. import { FetchSonDictionaryList, FetchDictionaryTree } from '@/api/system/dict'
  96. import { FetchFondsAll } from '@/api/system/fonds'
  97. import { FetchArchivesClassTree } from '@/api/system/archivesClass'
  98. import { FetchBatchUpdate } from '@/api/collect/collect'
  99. import Treeselect from '@riophae/vue-treeselect'
  100. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  101. export default {
  102. name: 'BlukEditing',
  103. components: { Treeselect },
  104. mixins: [],
  105. props: {
  106. selectedCategory: {
  107. type: Object,
  108. default: function() {
  109. return {}
  110. }
  111. },
  112. collectLevel: {
  113. type: Number,
  114. default: function() {
  115. return null
  116. }
  117. },
  118. selections: {
  119. type: Array,
  120. default: () => []
  121. }
  122. },
  123. data() {
  124. return {
  125. // 批量修改
  126. bulkEditingVisible: false,
  127. editForm: {
  128. updateField: '',
  129. updateType: 1,
  130. oldContext: '',
  131. updateContext: ''
  132. },
  133. fieldItemOptions: [],
  134. editTypeOptions: [{
  135. value: 1,
  136. label: '填充'
  137. }],
  138. dictionaryOptions: [],
  139. fondsOptions: [],
  140. classifyOptions: []
  141. }
  142. },
  143. computed: {
  144. editRules() {
  145. const validateRule = {
  146. updateField: [
  147. { required: true, message: '请选择修改字段', trigger: 'change' }
  148. ],
  149. updateType: [
  150. { required: true, message: '请选择修改方式', trigger: 'change' }
  151. ],
  152. oldContext: [
  153. { required: true, message: '请输入查询的内容', trigger: 'blur' }
  154. ],
  155. updateContext: [
  156. { required: true }
  157. ]
  158. }
  159. if (this.editForm.updateField.mateData !== null) {
  160. this.$set(validateRule, 'updateContext', [
  161. { required: true, message: '请选择更新内容', trigger: 'change' }
  162. ])
  163. } else if (this.editForm.updateField.isInputClass === 'date') {
  164. this.$set(validateRule, 'updateContext', [
  165. { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
  166. ])
  167. } else {
  168. this.$set(validateRule, 'updateContext', [
  169. { required: true, message: '请输入更新内容', trigger: 'blur' }
  170. ])
  171. }
  172. return validateRule
  173. }
  174. },
  175. watch: {
  176. 'editForm.updateField'(newVal) {
  177. this.$nextTick(() => {
  178. this.$refs.editForm.clearValidate()
  179. this.editForm.updateContext = ''
  180. this.editForm.updateType = 1
  181. if (newVal.mateData !== null || newVal.isInputClass === 'date') {
  182. this.editTypeOptions = [{
  183. value: 1,
  184. label: '填充'
  185. }]
  186. } else if (newVal.isInputClass === 'number') {
  187. this.editTypeOptions = [{
  188. value: 1,
  189. label: '填充'
  190. },
  191. {
  192. value: 2,
  193. label: '替换'
  194. },
  195. {
  196. value: 3,
  197. label: '增加'
  198. },
  199. {
  200. value: 4,
  201. label: '减少'
  202. }]
  203. } else {
  204. this.editTypeOptions = [{
  205. value: 1,
  206. label: '填充'
  207. },
  208. {
  209. value: 2,
  210. label: '替换'
  211. }]
  212. }
  213. })
  214. }
  215. },
  216. mounted() {
  217. this.$nextTick(() => {
  218. this.getInitCategoryInputFieldByPid()
  219. })
  220. },
  221. methods: {
  222. // 处理vue-treeSelect回显出现unknown问题
  223. getAutoNameUnknown(name) {
  224. if (name.lastIndexOf('unknown') > -1) {
  225. // 当treeselect翻译不了值时,name中有id,截取id,去调接口或者字典查询出名字
  226. return name.split('(')[0]
  227. } else {
  228. return name
  229. }
  230. },
  231. getInitCategoryInputFieldByPid() {
  232. const params = {
  233. 'categoryId': this.selectedCategory.id,
  234. 'categoryLevel': this.collectLevel
  235. }
  236. console.log(params)
  237. FetchInitCategoryInputFieldByPid(params).then(data => {
  238. this.fieldItemOptions = data
  239. })
  240. },
  241. selectField(val) {
  242. console.log(val)
  243. if (val.mateData === 3) {
  244. if (this.selectedCategory.arrangeType === 3 && val.fieldName === 'project_class') {
  245. this.getDictsList()
  246. } else {
  247. this.getSonDictionaryList(val.dictionaryId.id)
  248. }
  249. } else if (val.mateData === 1) {
  250. this.getFondsDatas()
  251. } else {
  252. this.getInitArchivesClass()
  253. }
  254. },
  255. getSonDictionaryList(dictionaryId) {
  256. FetchSonDictionaryList({ 'pid': dictionaryId }).then(res => {
  257. this.dictionaryOptions = res
  258. })
  259. },
  260. // 项目级别 - 阶段分类
  261. getDictsList() {
  262. FetchDictionaryTree().then((res) => {
  263. const filterCodes = ['project_class']
  264. let filteredItems = JSON.parse(JSON.stringify(res)).filter(item => filterCodes.includes(item.dictionaryCode))
  265. filteredItems = this.addLevelToDictionaryList(filteredItems, 1)
  266. if (this.selectedCategory.arrangeType === 3 && this.collectLevel !== 1) {
  267. this.dictionaryOptions = filteredItems
  268. } else {
  269. this.dictionaryOptions = this.filterData(filteredItems, filteredItems[0].id)
  270. }
  271. }).catch(err => {
  272. console.log(err)
  273. })
  274. },
  275. // 显示第一级和第二级
  276. filterData(data, targetId) {
  277. return data.filter(item => {
  278. if (item.id === targetId || item.dictionaryParents === targetId) {
  279. if (item.childDictionarys && item.childDictionarys.length > 0) {
  280. item.childDictionarys = this.filterData(item.childDictionarys, targetId)
  281. }
  282. return true
  283. }
  284. return false
  285. })
  286. },
  287. // 给筛选出来的数据加level 方便后面是否可点击
  288. addLevelToDictionaryList(dictionaryList, level) {
  289. dictionaryList.forEach(dictionary => {
  290. dictionary.level = level
  291. if (dictionary.childDictionarys) {
  292. dictionary.childDictionarys = this.addLevelToDictionaryList(dictionary.childDictionarys, level + 1)
  293. }
  294. })
  295. return dictionaryList
  296. },
  297. normalizerProject(node) {
  298. if ((node.childDictionarys && !node.childDictionarys.length) || node.childDictionarys === null) {
  299. delete node.childDictionarys
  300. }
  301. return {
  302. id: node.dictionaryName,
  303. label: node.dictionaryName,
  304. children: node.childDictionarys,
  305. isDisabled: (this.collectLevel !== 1 && node.level && node.level !== 3) || (this.collectLevel === 1 && node.level === 1)
  306. }
  307. },
  308. getFondsDatas() {
  309. FetchFondsAll().then(res => {
  310. this.fondsOptions = res
  311. })
  312. },
  313. getInitArchivesClass() {
  314. this.classifyOptions = []
  315. const params = {
  316. 'categoryId': this.selectedCategory.id
  317. }
  318. FetchArchivesClassTree(params).then((res) => {
  319. this.classifyOptions = JSON.parse(JSON.stringify(res))
  320. }).catch(err => {
  321. console.log(err)
  322. })
  323. },
  324. normalizer(node) {
  325. if (node.childArchivesClass === null) {
  326. delete node.childArchivesClass
  327. }
  328. return {
  329. id: node.code,
  330. label: node.name,
  331. children: node.childArchivesClass
  332. }
  333. },
  334. onSubmitBlukEditing(formName) {
  335. this.$refs[formName].validate((valid) => {
  336. if (valid) {
  337. const archivesIds = this.selections.map(item => item.id)
  338. console.log(this.editForm)
  339. const params = {
  340. 'archivesIds': archivesIds,
  341. 'categoryId': this.selectedCategory.id,
  342. 'categoryLevel': this.collectLevel,
  343. 'updateField': this.editForm.updateField.fieldName,
  344. 'oldContext': this.editForm.oldContext,
  345. 'updateContext': this.editForm.updateContext,
  346. 'updateType': this.editForm.updateType
  347. }
  348. console.log(params)
  349. FetchBatchUpdate(params).then(res => {
  350. this.$emit('close-dialog')
  351. this.handleCloseDialog()
  352. })
  353. } else {
  354. console.log('error submit!!')
  355. return false
  356. }
  357. })
  358. },
  359. handleCloseDialog(done) {
  360. // 重置表单数据
  361. this.$refs.editForm.resetFields()
  362. this.bulkEditingVisible = false
  363. // 关闭弹框
  364. // done()
  365. }
  366. }
  367. }
  368. </script>
  369. <style lang='scss' scoped>
  370. </style>