index.vue 8.9 KB

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