index.vue 11 KB

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