index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <!-- :exportList="exportList" -->
  3. <zj-page-container direction="row">
  4. <div class="catalogue">
  5. <div class="title">类型名称</div>
  6. <zj-page-container>
  7. <zj-page-fill>
  8. <el-tree :data="typeList" :props="defaultProps" default-expand-all :highlight-current="true"
  9. :expand-on-click-node="false" @node-click="handleNodeClick" current-node-key="ASSIST_UNIT"
  10. node-key="dictType" ref="listTree">
  11. </el-tree>
  12. </zj-page-fill>
  13. </zj-page-container>
  14. </div>
  15. <template-page ref="pageRef" :getList="getList" :columnParsing="columnParsing" :optionsEvensGroup="optionsEvensGroup"
  16. :tableAttributes="tableAttributes" :tableEvents="tableEvents" :operationColumnWidth="160" :operation="operation()" :exportList="exportList">
  17. <!-- <AddDataDictionary :visible="visible" :item="item" @setVisible="bool => {
  18. visible = bool
  19. if (!bool && item) {
  20. item = null
  21. }
  22. }
  23. " @success="() => {
  24. $refs.pageRef.refreshList()
  25. }
  26. " /> -->
  27. <el-dialog title="" width="500px" custom-class="diy-dialog" append-to-body :modal="true" :visible.sync="formDialog"
  28. :show-close="true" :close-on-click-modal="false" :modal-append-to-body="false" :before-close="formCancel">
  29. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  30. <zj-form-module :title="formDialogTitles[formDialogType]" label-width="100px" :showPackUp="false"
  31. :form-data="formData" :form-items="formItems" :disabled="formDialogType==2">
  32. </zj-form-module>
  33. </zj-form-container>
  34. <div slot="footer" class="dialog-footer">
  35. <el-button size="mini" @click="formCancel">取 消</el-button>
  36. <el-button size="mini" type="primary" @click="formConfirm()">确定</el-button>
  37. </div>
  38. </el-dialog>
  39. </template-page>
  40. </zj-page-container>
  41. </template>
  42. <script>
  43. import TemplatePage from '@/components/template/template-page-1.vue'
  44. import AddDataDictionary from './addDataDictionary.vue'
  45. import import_mixin from '@/components/template/import_mixin.js'
  46. import { required } from '@/components/template/rules_verify.js'
  47. import { commonTemplateDownload } from '@/api/common.js'
  48. import { getType, getDataDictionaryExport, getDataDictionary, add, edit, del, getDetail, listImport } from '@/api/dataDictionary.js'
  49. export default {
  50. components: {
  51. TemplatePage,
  52. AddDataDictionary
  53. },
  54. mixins: [import_mixin],
  55. data() {
  56. return {
  57. // 事件组合
  58. optionsEvensGroup: [
  59. [
  60. [
  61. {
  62. name: '新增',
  63. click: this.addData
  64. }
  65. ]
  66. ],
  67. [
  68. [
  69. {
  70. name: '下载导入模板',
  71. click: this.handleDownload
  72. }
  73. ],
  74. [
  75. {
  76. name: '导入模板',
  77. render: () => {
  78. return this.importButton(listImport, '导入模板')
  79. }
  80. }
  81. ],
  82. ]
  83. ],
  84. // 表格属性
  85. tableAttributes: {},
  86. // 表格事件
  87. tableEvents: {},
  88. visible: false,
  89. item: null,
  90. dictType: 'ASSIST_UNIT',
  91. dictTypeName: '辅材单位',
  92. typeList: [],
  93. defaultProps: {
  94. children: '',
  95. label: 'remark'
  96. },
  97. /** 表单变量 */
  98. formDialogType: 0,
  99. formDialogTitles: ["新增","编辑", "详情"],
  100. formDialog: false,
  101. formData: {
  102. companyName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
  103. dictType: 'ASSIST_UNIT',
  104. dictTypeName: '辅材单位',
  105. dictValue: '',
  106. status: 'ON',
  107. sortNum: '',
  108. remark: ''
  109. }
  110. }
  111. },
  112. created() {
  113. this.getType()
  114. },
  115. computed: {
  116. formItems() {
  117. return [{
  118. md: 24,
  119. isShow: true,
  120. name: 'el-input',
  121. attributes: { placeholder: '请输入', disabled: true },
  122. formItemAttributes: {
  123. label: '所属商户',
  124. prop: 'companyName',
  125. rules: [...required]
  126. },
  127. }, {
  128. md: 24,
  129. isShow: true,
  130. name: 'el-input',
  131. attributes: { placeholder: '请输入', disabled: true },
  132. formItemAttributes: {
  133. label: '类型名称',
  134. prop: 'dictTypeName',
  135. rules: [...required]
  136. },
  137. }, {
  138. md: 24,
  139. isShow: true,
  140. name: 'el-input',
  141. attributes: { placeholder: '请输入' },
  142. formItemAttributes: {
  143. label: '字典值',
  144. prop: 'dictValue',
  145. rules: [...required]
  146. },
  147. }, {
  148. md: 24,
  149. isShow: true,
  150. name: 'slot-component',
  151. attributes: { },
  152. formItemAttributes: {
  153. label: '状态',
  154. prop: 'status',
  155. rules: [...required]
  156. },
  157. render: (h, { props, onInput }) => {
  158. var { value } = props
  159. return (
  160. <el-radio-group v-model={this.formData.status}>
  161. <el-radio disabled={this.formDialogType==2} label="ON">启用</el-radio>
  162. <el-radio disabled={this.formDialogType==2} label="OFF">禁用</el-radio>
  163. </el-radio-group>
  164. )
  165. }
  166. },{
  167. md: 24,
  168. isShow: true,
  169. name: 'el-input',
  170. attributes: { placeholder: '请输入' },
  171. formItemAttributes: {
  172. label: '排序',
  173. prop: 'sortNum',
  174. rules: []
  175. },
  176. }, {
  177. md: 24,
  178. isShow: true,
  179. name: 'el-input',
  180. attributes: { placeholder: '请输入备注内容',type: "textarea", rows: 3 },
  181. formItemAttributes: {
  182. label: '备注',
  183. prop: 'remark',
  184. rules: []
  185. }
  186. }]
  187. }
  188. },
  189. methods: {
  190. // 列表请求函数
  191. getList(p) {
  192. try {
  193. var pam = JSON.parse(JSON.stringify(p))
  194. if (this.dictType) {
  195. pam.params.push({ "param": "a.dict_type", "compare": "=", "value": this.dictType })
  196. }
  197. return getDataDictionary(pam)
  198. } catch (error) {
  199. console.log(error)
  200. }
  201. },
  202. // 列表导出函数
  203. exportList: getDataDictionaryExport,
  204. getType(){
  205. getType().then(res => {
  206. this.typeList = res.data
  207. this.$refs.pageRef.refreshList()
  208. })
  209. },
  210. handleNodeClick(e){
  211. this.dictType = e.dictType
  212. this.formData.dictType = e.dictType
  213. this.formData.dictTypeName = e.remark
  214. this.dictTypeName = e.remark
  215. this.$refs.pageRef.refreshList()
  216. },
  217. // 表格列解析渲染数据更改
  218. columnParsing(item, defaultData) {
  219. return defaultData
  220. },
  221. operation() {
  222. if (true) {
  223. return (h, { row, index, column }) => {
  224. return (
  225. <div class="operation-btns">
  226. {true ? (
  227. <zj-button
  228. useLoading={false}
  229. parameter={[row]}
  230. buttonAttributes={{
  231. size: 'mini',
  232. type: 'primary'
  233. }}
  234. buttonEvents={{
  235. click: (...p) => {
  236. var [row] = p
  237. this.formData = row
  238. this.formDialogType = 1
  239. this.openForm()
  240. }
  241. }}
  242. >
  243. 编辑
  244. </zj-button>
  245. ) : null}
  246. {true ? (
  247. <el-popconfirm
  248. icon="el-icon-info"
  249. icon-color="red"
  250. title="这是一段内容确定删除吗?"
  251. onConfirm={() => {
  252. del({ id: row.sysDictId })
  253. .then(res => {
  254. this.$refs.pageRef.refreshList()
  255. this.$message({
  256. type: 'success',
  257. message: `删除成功!`
  258. })
  259. })
  260. .catch(err => {
  261. console.log(err)
  262. })
  263. }}
  264. >
  265. <zj-button
  266. slot="reference"
  267. buttonAttributes={{
  268. size: 'mini',
  269. type: 'danger'
  270. }}
  271. >
  272. 删除
  273. </zj-button>
  274. </el-popconfirm>
  275. ) : null}
  276. </div>
  277. )
  278. }
  279. }
  280. return undefined
  281. },
  282. addData() {
  283. this.formDialogType = 0
  284. this.openForm()
  285. },
  286. openForm() {
  287. this.formDialog = true;
  288. },
  289. formCancel() {
  290. this.$refs.formRef.$refs.inlineForm.clearValidate()
  291. this.$data.formData = this.$options.data().formData
  292. this.formData.dictType = this.dictType
  293. this.formData.dictTypeName = this.dictTypeName
  294. this.formDialog = false
  295. },
  296. formConfirm() {
  297. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  298. if (valid) {
  299. ([add, edit][this.formDialogType])(this.formData).then(res => {
  300. this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
  301. this.formCancel()
  302. this.$refs.pageRef.refreshList()
  303. })
  304. }
  305. })
  306. },
  307. // 下载导入模版
  308. handleDownload() {
  309. commonTemplateDownload({ name: '数据字典导入.xlsx' }, `${this.$route.meta.title}`).then(res => {
  310.     this.$message({
  311.         message: '下载成功',
  312.         type: 'success'
  313.     })
  314. }).catch(err => {
  315.     this.$message.error('下载失败')
  316. })
  317. },
  318. }
  319. }
  320. </script>
  321. <style lang="scss" scoped>
  322. .title{
  323. width: 120px;
  324. margin: 24px 0 20px 20px;
  325. padding-bottom: 10px;
  326. border-bottom: 1px solid #cccccc;
  327. font-weight: bold;
  328. }
  329. </style>