342afcd7529de68fe947f18ae00b608a3f8e085a.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <el-row :gutter="5" style="margin-top:5px;margin-left:5px;">
  3. <el-col :span="5">
  4. <el-card class="box-card">
  5. <div slot="header" class="clearfix" style="text-align: right; ">
  6. <el-row :gutter="2" style="margin-top:5px; margin-left:5px;">
  7. <el-col :span="12" style="text-align: left; vertical-align:middle; font-size: 20px"> <span>字典分类 </span></el-col>
  8. <el-col :span="6"> <el-col :span="6"> <el-button type="warning" icon="el-icon-edit-outline" size="mini" @click="jump" /></el-col>
  9. </el-col>
  10. <el-col :span="6"> <el-button type="primary" icon="el-icon-refresh" size="mini" /></el-col>
  11. </el-row>
  12. </div>
  13. <div class="component-item">
  14. <el-tree
  15. ref="tree"
  16. class="filter-tree"
  17. :data="parent"
  18. :props="defaultProps"
  19. default-expand-all
  20. @node-click="handleNodeClick"
  21. />
  22. </div>
  23. </el-card>
  24. </el-col>
  25. <el-col :span="19">
  26. <div class="app-container">
  27. <div class="filter-container">
  28. <el-button class="success" style="margin-left: 10px;" icon="el-icon-plus" @click="handleCreate"> 新增 </el-button>
  29. </div>
  30. <el-table
  31. v-loading="listLoading"
  32. element-loading-text="给我一点时间"
  33. :data="list"
  34. border
  35. fit
  36. highlight-current-row
  37. style="width: 100%;"
  38. :row-style="rowStyle"
  39. :cell-style="cellStyle"
  40. class="elTable"
  41. row-key="id"
  42. default-expand-all
  43. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  44. >
  45. <el-table-column label="名称" header-align="center" width="150px" align="center">
  46. <template slot-scope="scope">
  47. <span>{{ scope.row.label }}</span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="值" min-width="150px" header-align="center" align="center">
  51. <template slot-scope="scope">
  52. <span>{{ scope.row.value }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="顺序" min-width="150px" header-align="center" align="center">
  56. <template slot-scope="scope">
  57. <span>{{ scope.row.orderby }}</span>
  58. </template>
  59. </el-table-column>
  60. <!-- <el-table-column label="是否牧场" min-width="150px" header-align="center" align="center">
  61. <template slot-scope="scope">
  62. <el-switch
  63. v-model="scope.row.isPasture"
  64. :active-value="1"
  65. :inactive-value="0"
  66. @change="handleEnableChange(scope.$index, scope.row)"
  67. />
  68. </template>
  69. </el-table-column> -->
  70. <el-table-column label="启用" min-width="150px" header-align="center" align="center">
  71. <template slot-scope="scope">
  72. <el-switch
  73. v-model="scope.row.enable"
  74. active-color="#13ce66"
  75. inactive-color="#ff4949"
  76. :active-value="1"
  77. :inactive-value="0"
  78. @change="handleEnableChange(scope.$index, scope.row)"
  79. />
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="操作" header-align="center" align="center" width="260" class-name="small-padding fixed-width" fixed="right">
  83. <template slot-scope="{row}">
  84. <el-button type="primary" size="mini" @click="handleUpdate(row)">
  85. 编辑
  86. </el-button>
  87. <el-button v-if="row.status!='已删'" size="mini" type="danger" @click="handleDelete(row)">
  88. 删除
  89. </el-button>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. <pagination v-show="total>=0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="getList" />
  94. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
  95. <el-form
  96. ref="dataForm"
  97. v-enterToNext="true"
  98. :rules="rules"
  99. :model="deptform"
  100. label-position="left"
  101. label-width="100px"
  102. style="width: 600px; margin-left:50px;"
  103. >
  104. <el-form-item label="名称" prop="label">
  105. <el-input
  106. ref="label"
  107. v-model="deptform.label"
  108. />
  109. </el-form-item>
  110. <el-form-item label="值" prop="value">
  111. <el-input
  112. ref="value"
  113. v-model="deptform.value"
  114. />
  115. </el-form-item>
  116. <el-form-item label="顺序" prop="orderby">
  117. <el-input
  118. ref="orderby"
  119. v-model="deptform.orderby"
  120. />
  121. </el-form-item>
  122. <!-- <el-form-item label="是否牧场" prop="isPasture">
  123. <el-input
  124. ref="isPasture"
  125. v-model="deptform.isPasture"
  126. />
  127. </el-form-item> -->
  128. <el-form-item label="启用" prop="enable">
  129. <el-switch
  130. ref="enable"
  131. v-model="deptform.enable"
  132. active-color="#13ce66"
  133. inactive-color="#ff4949"
  134. :active-value="1"
  135. :inactive-value="0"
  136. />
  137. </el-form-item>
  138. </el-form>
  139. <div slot="footer" class="dialog-footer">
  140. <el-button
  141. v-if="dialogStatus==='create'"
  142. ref="createb"
  143. type="success"
  144. @click="createData_again()"
  145. >
  146. 确认新增
  147. </el-button>
  148. <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
  149. 确认
  150. </el-button>
  151. <el-button @click="dialogFormVisible = false">
  152. 关闭
  153. </el-button>
  154. </div>
  155. </el-dialog>
  156. </div>
  157. </el-col>
  158. </el-row>
  159. </template>
  160. <script>
  161. import waves from '@/directive/waves' // waves directive
  162. import enterToNext from '@/directive/enterToNext' // enterToNext directive
  163. import { PostDataByName, GetDataByName, getRecuData } from '@/api/common'
  164. import { isIntegerZero } from '@/utils/validate'
  165. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  166. import { MessageBox } from 'element-ui'
  167. export default {
  168. name: 'Dict',
  169. components: { Pagination },
  170. directives: { waves, enterToNext },
  171. data() {
  172. return {
  173. defaultProps: {
  174. children: 'children',
  175. label: 'name'
  176. },
  177. dictid: 0,
  178. list: [],
  179. total: 0,
  180. listLoading: true,
  181. requestParam: {
  182. name: '',
  183. params: []
  184. },
  185. deptform: {
  186. label: '',
  187. value: '',
  188. orderby: '',
  189. enable: '',
  190. pid: ''
  191. },
  192. getdataListParm: { name: 'getDictList',
  193. offset: 1,
  194. pagecount: 8,
  195. params: [] },
  196. getRecuListParm: { name: 'getDictclass',
  197. idname: 'id',
  198. params: [-1] },
  199. rules: {
  200. label: [{ type: 'string', required: true, message: '名称必填', trigger: 'change' }],
  201. value: [{ type: 'string', required: true, message: '只必填', trigger: 'change' }],
  202. orderby: [{ validator: isIntegerZero, trigger: 'blur' }]
  203. },
  204. dialogFormVisible: false,
  205. parentDeptVisible: true,
  206. dialogStatus: '',
  207. textMap: {
  208. update: '编辑',
  209. create: '新增'
  210. },
  211. parent: [],
  212. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  213. cellStyle: { padding: 0 + 'px' }
  214. }
  215. },
  216. created() {
  217. this.getList()
  218. },
  219. methods: {
  220. jump() {
  221. this.$router.push('/console/menu')
  222. // 传递的参数用{{ $route.query.goodsId }}获取
  223. // this.$router.push({ path: '/cart?goodsId=12' })
  224. // this.$router.go(-2)
  225. // 后退两步
  226. },
  227. handleNodeClick(data) {
  228. if (data.children.length === 0) {
  229. this.listLoading = true
  230. this.dictid = data.id
  231. this.getdataListParm.params = [data.id, data.id]
  232. GetDataByName(this.getdataListParm).then(response => {
  233. this.list = response.data.list
  234. this.total = response.data.total
  235. // Just to simulate the time of the request
  236. setTimeout(() => {
  237. this.listLoading = false
  238. }, 100)
  239. })
  240. }
  241. },
  242. getDownList() {
  243. getRecuData(this.getRecuListParm).then(response => {
  244. this.parent = response.data
  245. })
  246. },
  247. getList() {
  248. this.listLoading = true
  249. this.getDownList()
  250. GetDataByName(this.getdataListParm).then(response => {
  251. this.list = response.data.list
  252. this.total = response.data.total
  253. setTimeout(() => {
  254. this.listLoading = false
  255. }, 100)
  256. })
  257. },
  258. resetRequestParam() {
  259. this.deptform.id = ''
  260. this.deptform.pid = ''
  261. this.deptform.label = ''
  262. this.deptform.value = ''
  263. this.deptform.orderby = '0'
  264. this.deptform.enable = '1'
  265. },
  266. handleCreate() {
  267. this.resetRequestParam()
  268. this.dialogStatus = 'create'
  269. this.deptform.orderby = '0'
  270. this.deptform.enable = 1
  271. this.dialogFormVisible = true
  272. this.$nextTick(() => {
  273. this.$refs['dataForm'].clearValidate()
  274. this.$refs['label'].focus()
  275. })
  276. },
  277. createData() {
  278. this.$refs['dataForm'].validate((valid) => {
  279. if (valid) {
  280. this.requestParam.name = 'insertDictList'
  281. this.requestParam.params = []
  282. this.requestParam.params[0] = this.deptform.label
  283. this.requestParam.params[1] = this.deptform.value
  284. this.requestParam.params[2] = this.deptform.orderby
  285. this.requestParam.params[3] = this.deptform.enable
  286. this.requestParam.params[4] = this.dictid
  287. PostDataByName(this.requestParam).then(() => {
  288. this.getList()
  289. this.dialogFormVisible = false
  290. this.$notify({
  291. title: '成功',
  292. message: '新增成功',
  293. type: 'success',
  294. duration: 2000
  295. })
  296. })
  297. }
  298. })
  299. },
  300. createData_again() {
  301. this.$refs['dataForm'].validate((valid) => {
  302. if (valid) {
  303. this.requestParam.name = 'insertDictList'
  304. this.requestParam.params = []
  305. this.requestParam.params[0] = this.deptform.label
  306. this.requestParam.params[1] = this.deptform.value
  307. this.requestParam.params[2] = this.deptform.orderby
  308. this.requestParam.params[3] = this.deptform.enable
  309. this.requestParam.params[4] = this.dictid
  310. PostDataByName(this.requestParam).then(() => {
  311. this.$nextTick(() => {
  312. this.$refs['label'].focus()
  313. })
  314. this.getList()
  315. this.resetRequestParam()
  316. this.deptform.orderby = '0'
  317. this.deptform.enable = 1
  318. this.$notify({
  319. title: '成功',
  320. message: '新增成功',
  321. type: 'success',
  322. duration: 2000
  323. })
  324. })
  325. }
  326. })
  327. },
  328. handleUpdate(row) {
  329. this.deptform.id = row.id
  330. this.deptform.label = row.label
  331. this.deptform.value = row.value
  332. this.deptform.orderby = row.orderby
  333. this.deptform.enable = row.enable
  334. this.deptform.pid = row.pid
  335. this.dialogStatus = 'update'
  336. this.dialogFormVisible = true
  337. this.$nextTick(() => {
  338. this.$refs['dataForm'].clearValidate()
  339. this.$refs['label'].focus()
  340. })
  341. },
  342. updateData() {
  343. this.$refs['dataForm'].validate((valid) => {
  344. if (valid) {
  345. this.requestParam.name = 'updateDictList'
  346. this.requestParam.params = []
  347. this.requestParam.params[0] = this.deptform.label
  348. this.requestParam.params[1] = this.deptform.value
  349. this.requestParam.params[2] = this.deptform.orderby
  350. this.requestParam.params[3] = this.deptform.enable
  351. this.requestParam.params[4] = this.dictid
  352. this.requestParam.params[5] = this.deptform.id
  353. PostDataByName(this.requestParam).then(() => {
  354. this.getList()
  355. this.resetRequestParam()
  356. this.dialogFormVisible = false
  357. this.$notify({
  358. title: '成功',
  359. message: '修改成功',
  360. type: 'success',
  361. duration: 2000
  362. })
  363. })
  364. }
  365. })
  366. },
  367. handleEnableChange(index, row) {
  368. this.requestParam.name = 'updateDictList'
  369. this.requestParam.params = []
  370. this.requestParam.params[0] = row.label
  371. this.requestParam.params[1] = row.value
  372. this.requestParam.params[2] = row.orderby
  373. this.requestParam.params[3] = row.enable
  374. this.requestParam.params[4] = this.dictid
  375. this.requestParam.params[5] = row.id
  376. PostDataByName(this.requestParam).then(() => {
  377. this.$notify({
  378. title: '成功',
  379. message: '修改成功',
  380. type: 'success',
  381. duration: 2000
  382. })
  383. })
  384. },
  385. handleDelete(row) {
  386. MessageBox.confirm('名称:' + row.label, '确认删除?', {
  387. confirmButtonText: '确认',
  388. cancelButtonText: '取消',
  389. type: 'warning'
  390. }).then(() => {
  391. this.requestParam.name = 'deleteDictList'
  392. this.requestParam.params = []
  393. this.requestParam.params[0] = row.id
  394. PostDataByName(this.requestParam).then(() => {
  395. this.getList()
  396. this.resetRequestParam()
  397. this.dialogFormVisible = false
  398. this.$notify({
  399. title: '成功',
  400. message: '删除成功',
  401. type: 'success',
  402. duration: 2000
  403. })
  404. })
  405. }).catch(() => {
  406. this.$message({
  407. type: 'info',
  408. message: '已取消删除'
  409. })
  410. })
  411. }
  412. }
  413. }
  414. </script>