index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <template>
  2. <div class="app-container">
  3. <div class="app-container">
  4. <div class="filter-container">
  5. <el-select
  6. v-model="getdataListParm.parammaps.pastureName"
  7. placeholder="牧场"
  8. style="width:120px"
  9. class="filter-item"
  10. >
  11. <el-option
  12. v-for="item in findAllPasture"
  13. :key="item.id"
  14. :label="item.name"
  15. :value="item.name"
  16. />
  17. </el-select>
  18. <el-input v-model="getdataListParm.parammaps.empCode" placeholder="工号" style="width: 140px;" class="filter-item" />
  19. <el-input v-model="getdataListParm.parammaps.empname" placeholder="姓名" style="width: 140px;" class="filter-item" />
  20. <el-input v-model="getdataListParm.parammaps.position" placeholder="职位" style="width: 140px;" class="filter-item" />
  21. <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_search">搜索</el-button>
  22. <el-button v-if="isEmpAdd" class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="form_add">新增</el-button>
  23. <el-button class="filter-item" type="success" icon="el-icon-download" style="" @click="handleDownload">导出</el-button>
  24. </div>
  25. <el-table
  26. v-loading="listLoading"
  27. element-loading-text="给我一点时间"
  28. :data="list"
  29. border
  30. fit
  31. highlight-current-row
  32. style="width: 100%;"
  33. :row-style="rowStyle"
  34. :cell-style="cellStyle"
  35. class="elTable"
  36. row-key="id"
  37. default-expand-all
  38. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  39. @sort-change="tableSort"
  40. :max-height="myHeight"
  41. >
  42. <el-table-column label="序号" align="center" type="index" width="50px">
  43. <template slot-scope="scope">
  44. <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="姓名" min-width="110px" header-align="center" align="center">
  48. <template slot-scope="scope">
  49. <span>{{ scope.row.empname }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="EAS账户名" header-align="center" width="120px" align="center">
  53. <template slot-scope="scope">
  54. <span>{{ scope.row.easName }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="牧场" min-width="100px" header-align="center" align="center">
  58. <template slot-scope="scope">
  59. <span>{{ scope.row.pastureName }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="部门" min-width="100px" header-align="center" align="center">
  63. <template slot-scope="scope">
  64. <span>{{ scope.row.deptname }}</span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="工号" min-width="100px" header-align="center" align="center">
  68. <template slot-scope="scope">
  69. <span>{{ scope.row.empCode }}</span>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="职位" min-width="100px" header-align="center" align="center">
  73. <template slot-scope="scope">
  74. <span>{{ scope.row.position }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="电话" min-width="130px" header-align="center" align="center">
  78. <template slot-scope="scope">
  79. <span>{{ scope.row.tel }}</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="状态" min-width="130px" header-align="center" align="center">
  83. <template slot-scope="scope">
  84. <span>{{ scope.row.state }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="账号数" sortable prop="isuser" min-width="90px" header-align="center" align="center">
  88. <template slot-scope="scope">
  89. <span>{{ scope.row.isuser }}</span>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="操作" header-align="center" align="center" width="260" class-name="small-padding fixed-width" fixed="right">
  93. <template slot-scope="{row}">
  94. <el-button v-if="isEmpUpdate" type="primary" size="mini" @click="form_edit(row)">编辑</el-button>
  95. <el-button v-if="row.status!='已删' && isEmpDel" size="mini" type="danger" @click="form_delete(row)">删除</el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. <pagination
  100. v-show="total>0"
  101. :total="total"
  102. :page.sync="getdataListParm.offset"
  103. :limit.sync="getdataListParm.pagecount"
  104. @pagination="get_table_data"
  105. />
  106. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
  107. <el-form
  108. ref="dataForm"
  109. v-enterToNext="true"
  110. :rules="rules"
  111. :model="dataform"
  112. label-position="left"
  113. label-width="100px"
  114. style="width: 600px; margin-left:50px;"
  115. >
  116. <el-form-item label="用户名" prop="empname">
  117. <el-input ref="empname" v-model="dataform.empname" />
  118. </el-form-item>
  119. <el-form-item label="EAS账户名" prop="easName">
  120. <el-input ref="easName" v-model="dataform.easName" />
  121. </el-form-item>
  122. <el-form-item label="部门" prop="deptid">
  123. <tree-select
  124. :disabled="disabled"
  125. :height="280"
  126. :width="200"
  127. size="small"
  128. :data="parentDept"
  129. :default-props="defaultProps"
  130. :node-key="nodeKey"
  131. :checked-keys="defaultCheckedKeys"
  132. @popoverHide="popoverHide"
  133. />
  134. </el-form-item>
  135. <el-form-item label="职位" prop="position">
  136. <el-input ref="position" v-model="dataform.position" />
  137. </el-form-item>
  138. <el-form-item label="工号" prop="empCode">
  139. <el-input ref="empCode" v-model="dataform.empCode" />
  140. </el-form-item>
  141. <!-- <el-form-item label="状态" prop="state">
  142. <el-input ref="state" v-model="dataform.state" />
  143. </el-form-item> -->
  144. <el-form-item label="联系方式" prop="tel">
  145. <el-input ref="tel" v-model="dataform.tel" />
  146. </el-form-item>
  147. <el-form-item label="备注" prop="remark">
  148. <el-input ref="remark" v-model="dataform.remark" />
  149. </el-form-item>
  150. <el-form-item label="顺序" prop="sort">
  151. <el-input
  152. ref="sort"
  153. v-model="dataform.sort"
  154. />
  155. </el-form-item>
  156. <!-- <el-form-item label="启用" prop="enable">
  157. <el-switch
  158. ref="enable"
  159. v-model="dataform.enable"
  160. active-color="#13ce66"
  161. inactive-color="#ff4949"
  162. :active-value="1"
  163. :inactive-value="0"
  164. />
  165. </el-form-item> -->
  166. </el-form>
  167. <div slot="footer" class="dialog-footer">
  168. <el-button v-if="dialogStatus==='create'" ref="createb" type="success" @click="add_dialog_save_again()">确认新增</el-button>
  169. <el-button type="primary" @click="dialogStatus==='create'?add_dialog_save():edit_dialog_save()">确认</el-button>
  170. <el-button @click="dialogFormVisible = false;get_table_data()">关闭</el-button>
  171. </div>
  172. </el-dialog>
  173. </div>
  174. </div>
  175. </template>
  176. <script>
  177. import TreeSelect from '@/components/TreeSelect'
  178. import waves from '@/directive/waves' // waves directive
  179. // eslint-disable-next-line no-unused-vars
  180. import { isIntegerZero } from '@/utils/validate'
  181. import { validatePhoneTwo } from '@/utils/validate'
  182. import enterToNext from '@/directive/enterToNext' // enterToNext directive
  183. import { PostDataByName, GetDataByName, getRecuData, GetDataByNames, checkButtons, failproccess,GetAccount } from '@/api/common'
  184. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  185. import { MessageBox } from 'element-ui'
  186. import Cookies from 'js-cookie'
  187. import { sortChange, json2excel } from '@/utils/index.js'
  188. export default {
  189. name: 'Emp',
  190. components: { Pagination, TreeSelect },
  191. directives: { waves, enterToNext },
  192. data() {
  193. return {
  194. myHeight:document.documentElement.clientHeight - 85- 150,
  195. isEmpAdd: [],
  196. isEmpUpdate: [],
  197. isEmpDel: [],
  198. disabled: false,
  199. tableKey: 0,
  200. list: [{ sqlname: '', id: 0, sqlstr: '' }],
  201. parentDept: [],
  202. total: 0,
  203. listLoading: true,
  204. requestParam: {
  205. name: 'createapisql',
  206. offset: 0,
  207. pagecount: 0,
  208. parammaps: []
  209. },
  210. dataform: {
  211. position: '',
  212. empname: '',
  213. deptname: '',
  214. deptid: '',
  215. tel: '',
  216. remark: '',
  217. id: '',
  218. sort: '',
  219. parentid: '',
  220. enable: '1',
  221. empCode: '',
  222. easName: ''
  223. },
  224. getDeptParm: { name: 'getdeptrecu', idname: 'value', params: [Cookies.get('pastureid')] },
  225. getdataListParm: {
  226. name: 'getEmpAllL',
  227. page: 1,
  228. offset: 1,
  229. pagecount: 10,
  230. returntype: 'Map',
  231. parammaps: {
  232. empname: '',
  233. empCode: '',
  234. pastureId: Cookies.get('pastureid'),
  235. pastureName: Cookies.get('pasturename')
  236. }
  237. },
  238. getdataListParmSH: {
  239. name: 'getEmpAllL',
  240. page: 0,
  241. offset: 0,
  242. pagecount: 0,
  243. returntype: 'Map',
  244. parammaps: {
  245. empname: '',
  246. empCode: '',
  247. pastureId: Cookies.get('pastureid'),
  248. pastureName: Cookies.get('pasturename')
  249. }
  250. },
  251. rules: {
  252. empname: [{ type: 'string', required: true, message: '必填', trigger: 'change' }],
  253. empCode: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  254. tel: [
  255. {
  256. type: 'number',
  257. required: true,
  258. message: '请输入正确的格式',
  259. trigger: 'change'
  260. }
  261. ],
  262. sort: [{ validator: isIntegerZero, trigger: 'blur' }],
  263. // eslint-disable-next-line no-dupe-keys
  264. tel: [{ validator: validatePhoneTwo, trigger: 'blur' }]
  265. },
  266. // 2-3:下拉框请求后数据加入[]
  267. findAllPasture: [],
  268. // 2-1.请求下拉框接口
  269. requestParams: [
  270. { name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }}
  271. ],
  272. dialogFormVisible: false,
  273. selectedRole: '',
  274. dialogStatus: '',
  275. textMap: {
  276. update: '编辑',
  277. create: '新增'
  278. },
  279. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  280. cellStyle: { padding: 0 + 'px' },
  281. defaultProps: {
  282. children: 'children',
  283. label: 'label'
  284. },
  285. nodeKey: 'value',
  286. defaultCheckedKeys: [],
  287. pageNum: 0,
  288. pageSize: 10
  289. }
  290. },
  291. created() {
  292. this.get_table_data()
  293. this.get_auto_buttons()
  294. },
  295. methods: {
  296. tableSort(column) {
  297. sortChange(column, this.list)
  298. },
  299. get_auto_buttons() {
  300. // 新增
  301. const EmpAdd = 'console:emp:add'
  302. const isEmpAdd = checkButtons(this.$store.state.user.buttons, EmpAdd)
  303. this.isEmpAdd = isEmpAdd
  304. // 编辑
  305. const EmpUpdate = 'console:emp:update'
  306. const isEmpUpdate = checkButtons(this.$store.state.user.buttons, EmpUpdate)
  307. this.isEmpUpdate = isEmpUpdate
  308. // 删除
  309. const EmpDel = 'console:emp:del'
  310. const isEmpDel = checkButtons(this.$store.state.user.buttons, EmpDel)
  311. this.isEmpDel = isEmpDel
  312. },
  313. popoverHide(checkedIds, checkedData) {
  314. console.log(checkedIds, checkedData)
  315. this.dataform.pastureId = checkedData.pastureId
  316. this.dataform.deptid = checkedIds
  317. this.dataform.parentid = checkedData.parentid
  318. },
  319. deptenter() {
  320. this.$nextTick(() => {
  321. this.$refs['remark'].focus()
  322. })
  323. },
  324. get_table_data() {
  325. this.listLoading = true
  326. GetDataByName(this.getdataListParm).then(response => {
  327. this.list = response.data.list
  328. this.pageNum = response.data.pageNum
  329. this.pageSize = response.data.pageSize
  330. if (response.data.total) {
  331. this.total = response.data.total
  332. }
  333. this.get_select_list()
  334. this.getDeptList()
  335. // Just to simulate the time of the request
  336. setTimeout(() => {
  337. this.listLoading = false
  338. }, 0.5 * 1000)
  339. })
  340. },
  341. // 2-2:下拉框
  342. get_select_list() {
  343. GetDataByNames(this.requestParams).then(response => {
  344. this.findAllPasture = response.data.findAllPasture.list
  345. })
  346. },
  347. form_search() {
  348. this.listLoading = true
  349. this.getdataListParm.offset = 1
  350. this.get_table_data()
  351. },
  352. getDeptList() {
  353. getRecuData(this.getDeptParm).then(response => {
  354. this.parentDept = response.data
  355. })
  356. },
  357. resetRequestParam() {
  358. this.dataform.easName = ''
  359. this.dataform.empname = ''
  360. this.dataform.deptname = ''
  361. this.dataform.parentid = ''
  362. this.dataform.deptid = ''
  363. this.dataform.position = ''
  364. this.dataform.tel = ''
  365. this.dataform.remark = ''
  366. this.dataform.empCode = ''
  367. this.dataform.id = ''
  368. this.dataform.sort = '0'
  369. this.dataform.enable = '1'
  370. this.defaultCheckedKeys = []
  371. },
  372. form_add() {
  373. this.resetRequestParam()
  374. this.dialogStatus = 'create'
  375. this.dialogFormVisible = true
  376. this.$nextTick(() => {
  377. this.$refs['dataForm'].clearValidate()
  378. })
  379. },
  380. add_dialog_save() {
  381. console.log(this.dataform)
  382. this.$refs['dataForm'].validate(valid => {
  383. if (valid) {
  384. if (this.dataform.deptid == '') {
  385. this.$message({ type: 'error', message: '部门必填', duration: 2000 })
  386. return false
  387. }
  388. this.requestParam.name = 'createEmp'
  389. this.requestParam.parammaps = {}
  390. if (this.dataform.easName == '') { this.dataform.easName = this.dataform.empname }
  391. this.requestParam.parammaps.easName = this.dataform.easName
  392. this.requestParam.parammaps.empname = this.dataform.empname
  393. this.requestParam.parammaps.deptid = this.dataform.deptid
  394. this.requestParam.parammaps.tel = this.dataform.tel
  395. this.requestParam.parammaps.position = this.dataform.position
  396. this.requestParam.parammaps.remark = this.dataform.remark
  397. this.requestParam.parammaps.sort = this.dataform.sort
  398. this.requestParam.parammaps.enable = this.dataform.enable
  399. this.requestParam.parammaps.pastureId = this.dataform.pastureId
  400. this.requestParam.parammaps.empCode = this.dataform.empCode
  401. PostDataByName(this.requestParam).then(response => {
  402. if (response.msg !== 'fail') {
  403. this.get_table_data()
  404. this.dialogFormVisible = false
  405. this.$notify({ title: '成功', message: '新增成功', type: 'success', duration: 2000 })
  406. } else {
  407. var Duplicate = new RegExp('Duplicate')
  408. if (Duplicate.test(response.data)) {
  409. this.$notify({ title: '', message: '此员工已存在', type: 'warning', duration: 2000 })
  410. } else {
  411. failproccess(response, this.$notify)
  412. }
  413. }
  414. })
  415. }
  416. })
  417. },
  418. add_dialog_save_again() {
  419. this.$refs['dataForm'].validate(valid => {
  420. if (valid) {
  421. if (this.dataform.deptid == '') {
  422. this.$message({ type: 'error', message: '部门必填', duration: 2000 })
  423. return false
  424. }
  425. this.requestParam.name = 'createEmp'
  426. this.requestParam.parammaps = {}
  427. if (this.dataform.easName == '') { this.dataform.easName = this.dataform.empname }
  428. this.requestParam.parammaps.easName = this.dataform.easName
  429. this.requestParam.parammaps.empname = this.dataform.empname
  430. this.requestParam.parammaps.deptid = this.dataform.deptid
  431. this.requestParam.parammaps.tel = this.dataform.tel
  432. this.requestParam.parammaps.position = this.dataform.position
  433. this.requestParam.parammaps.remark = this.dataform.remark
  434. this.requestParam.parammaps.sort = this.dataform.sort
  435. this.requestParam.parammaps.enable = this.dataform.enable
  436. this.requestParam.parammaps.pastureId = this.dataform.pastureId
  437. this.requestParam.parammaps.empCode = this.dataform.empCode
  438. PostDataByName(this.requestParam).then(response => {
  439. if (response.msg !== 'fail') {
  440. this.get_table_data()
  441. this.resetRequestParam()
  442. this.$notify({ title: '成功', message: '新增成功', type: 'success', duration: 2000 })
  443. } else {
  444. var Duplicate = new RegExp('Duplicate')
  445. if (Duplicate.test(response.data)) {
  446. this.$notify({ title: '', message: '此员工已存在', type: 'warning', duration: 2000 })
  447. } else {
  448. failproccess(response, this.$notify)
  449. }
  450. }
  451. })
  452. }
  453. })
  454. },
  455. form_edit(row) {
  456. console.log(row)
  457. this.dataform = Object.assign(row, {})
  458. this.defaultCheckedKeys = [this.dataform.deptid]
  459. this.dialogStatus = 'update'
  460. this.dialogFormVisible = true
  461. this.$nextTick(() => {
  462. this.$refs['dataForm'].clearValidate()
  463. })
  464. },
  465. edit_dialog_save() {
  466. this.$refs['dataForm'].validate(valid => {
  467. if (valid) {
  468. this.requestParam.name = 'updateEmp'
  469. this.requestParam.parammaps = {}
  470. if (this.dataform.easName == '' || this.dataform.easName == undefined) { this.dataform.easName = this.dataform.empname }
  471. this.requestParam.parammaps.easName = this.dataform.easName
  472. this.requestParam.parammaps.empname = this.dataform.empname
  473. this.requestParam.parammaps.deptid = this.dataform.deptid
  474. this.requestParam.parammaps.tel = this.dataform.tel
  475. this.requestParam.parammaps.position = this.dataform.position
  476. this.requestParam.parammaps.remark = this.dataform.remark
  477. this.requestParam.parammaps.sort = this.dataform.sort
  478. this.requestParam.parammaps.enable = this.dataform.enable
  479. this.requestParam.parammaps.pastureId = this.dataform.pastureId
  480. this.requestParam.parammaps.empCode = this.dataform.empCode
  481. this.requestParam.parammaps.id = this.dataform.id
  482. PostDataByName(this.requestParam).then(() => {
  483. this.get_table_data()
  484. this.resetRequestParam()
  485. this.dialogFormVisible = false
  486. })
  487. }
  488. })
  489. },
  490. handleDownload() {
  491. this.$alert('员工信息正在导出中,请勿刷新或离开本页面,若导出时间过长,建议缩小导出数据范围重新导出', {})
  492. this.isPercentage = true
  493. this.percentage = 1
  494. var timer = setInterval(() => {
  495. this.percentage += 5
  496. if (this.percentage > 95) {
  497. this.percentage = 99
  498. clearInterval(timer)
  499. }
  500. this.percentage = this.percentage
  501. }, 1000)
  502. this.getdataListParmSH.parammaps = this.getdataListParm.parammaps
  503. // GetDataByName(this.getdataListParm)
  504. GetAccount(this.getdataListParmSH).then(response => {
  505. this.downLoadList = response.data.list
  506. if (response.data.list !== '') {
  507. this.percentage = 99
  508. setTimeout(() => {
  509. this.isPercentage = false
  510. }, 2000)
  511. }
  512. console.log(this.downLoadList)
  513. const elecExcelDatas = [
  514. {
  515. tHeader: ['牧场', '姓名', '部门', '职位', '电话','状态', '工号'],
  516. filterVal: ['pastureName', 'empname', 'deptname', 'position', 'tel','state', 'empCode'],
  517. tableDatas: this.downLoadList,
  518. sheetName: '员工信息'
  519. }
  520. ]
  521. json2excel(elecExcelDatas, '员工信息', true, 'xlsx')
  522. })
  523. },
  524. form_delete(row) {
  525. MessageBox.confirm('名称:' + row.empname, '确认删除?', {
  526. confirmButtonText: '确认',
  527. cancelButtonText: '取消',
  528. type: 'warning'
  529. }).then(() => {
  530. this.requestParam.name = 'deleteEmp'
  531. this.requestParam.parammaps = {}
  532. this.requestParam.parammaps.id = row.id
  533. // this.requestParam.params[1] = this.$store.state.user.pastureid
  534. PostDataByName(this.requestParam).then(response => {
  535. if (response.msg !== 'fail') {
  536. this.get_table_data()
  537. this.resetRequestParam()
  538. this.dialogFormVisible = false
  539. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  540. } else {
  541. this.$notify({ title: '失败', message: '删除失败-' + response.data, type: 'danger', duration: 2000 })
  542. }
  543. })
  544. })
  545. }
  546. }
  547. }
  548. </script>