167a418bbf9f5afd1a684b4933637b95bf6589a7.svn-base 15 KB

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