pfperson.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <div class="branch">
  3. <el-form
  4. :inline="true"
  5. :model="dataForm"
  6. @keyup.enter.native="getDataList()">
  7. <el-form-item>
  8. <el-input
  9. v-model="dataForm.key"
  10. placeholder="用户名/用户操作"
  11. clearable
  12. ></el-input>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button @click="getDataList()">查询</el-button>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button v-if="isAuth('sys:role:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button v-if="isAuth('sys:role:delete')" type="danger" @click="deleteHandle()" :disabled="selectionDataList.length <= 0">批量删除</el-button>
  22. </el-form-item>
  23. </el-form>
  24. <el-table
  25. :data="dataList"
  26. @selection-change="selectionChangeHandle"
  27. v-loading="dataListLoading"
  28. style="width: 100%">
  29. <el-table-column
  30. type="selection"
  31. header-align="center"
  32. align="center"
  33. width="50">
  34. </el-table-column>
  35. <el-table-column
  36. prop="name"
  37. header-align="center"
  38. align="center"
  39. label="养殖员姓名">
  40. </el-table-column>
  41. <el-table-column
  42. prop="position"
  43. header-align="center"
  44. align="center"
  45. label="职位">
  46. </el-table-column>
  47. <el-table-column
  48. prop="approachTime"
  49. header-align="center"
  50. align="center"
  51. label="入场时间">
  52. </el-table-column>
  53. <el-table-column
  54. prop="departureTime"
  55. header-align="center"
  56. align="center"
  57. label="离场时间">
  58. </el-table-column>
  59. <el-table-column
  60. header-align="center"
  61. align="center"
  62. label="当前在职">
  63. <template slot-scope="scope">
  64. {{scope.row.jobStatus? '是': '否'}}
  65. </template>
  66. </el-table-column>
  67. <el-table-column
  68. fixed="right"
  69. header-align="center"
  70. align="center"
  71. label="操作">
  72. <template slot-scope="scope">
  73. <el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row)">修改</el-button>
  74. <el-button v-if="isAuth('sys:user:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
  75. </template>
  76. </el-table-column>
  77. </el-table>
  78. <el-dialog
  79. :title="!form.id ? '新增' : '修改'"
  80. :close-on-click-modal="false"
  81. :visible.sync="visible"
  82. @close="cancel">
  83. <el-form :model="form" ref="form" @keyup.enter.native="formSubmit()" label-width="80px">
  84. <el-form-item label="姓名">
  85. <el-input v-model="form.name" placeholder="养殖员姓名"></el-input>
  86. </el-form-item>
  87. <el-form-item label="职位">
  88. <el-input v-model="form.position" placeholder="职位"></el-input>
  89. </el-form-item>
  90. <el-form-item label="当前在职">
  91. <el-select v-model="form.jobStatus" placeholder="请选择当前是否在岗">
  92. <el-option
  93. v-for="item in options"
  94. :key="item.value"
  95. :label="item.label"
  96. :value="item.value">
  97. </el-option>
  98. </el-select>
  99. </el-form-item>
  100. <el-form-item label="入场时间">
  101. <el-date-picker
  102. v-model="form.approachTime"
  103. type="datetime"
  104. value-format="yyyy-MM-dd HH:mm:ss"
  105. placeholder="选择日期时间">
  106. </el-date-picker>
  107. </el-form-item>
  108. <el-form-item label="离场时间">
  109. <el-date-picker
  110. v-model="form.departureTime"
  111. type="datetime"
  112. value-format="yyyy-MM-dd HH:mm:ss"
  113. placeholder="选择日期时间">
  114. </el-date-picker>
  115. </el-form-item>
  116. </el-form>
  117. <span slot="footer" class="dialog-footer">
  118. <el-button @click="cancel">取消</el-button>
  119. <el-button type="primary" @click="formSubmit()">确定</el-button>
  120. </span>
  121. </el-dialog>
  122. </div>
  123. </template>
  124. <script>
  125. export default {
  126. data () {
  127. return {
  128. dataForm: {
  129. key: ''
  130. },
  131. dataList: [
  132. {
  133. buildTime: '',
  134. id: '',
  135. location: '',
  136. manager: '',
  137. name: '',
  138. }
  139. ],
  140. pageIndex: 1,
  141. pageSize: 10,
  142. totalPage: 0,
  143. dataListLoading: false,
  144. selectionDataList: [],
  145. visible: false,
  146. form: {
  147. id: '',
  148. name: '',
  149. position: '',
  150. approachTime: '',
  151. departureTime: '',
  152. jobStatus: ''
  153. },
  154. options: [
  155. {
  156. value: true,
  157. label: '是'
  158. },
  159. {
  160. value: false,
  161. label: '否'
  162. }
  163. ],
  164. pigs: []
  165. }
  166. },
  167. created () {
  168. this.getDataList()
  169. },
  170. mounted () {
  171. // this.getCascader()
  172. },
  173. methods: {
  174. // 获取数据列表
  175. getDataList () {
  176. this.dataListLoading = true
  177. this.$http({
  178. url: this.$http.adornUrl('/management/employee/list'),
  179. method: 'post',
  180. params: this.$http.adornParams({
  181. page: 1,
  182. limit: 10,
  183. keywords: this.dataForm.key
  184. })
  185. }).then(({ data }) => {
  186. console.log(data);
  187. if (data && data.code === 0) {
  188. this.dataList = data.page.list
  189. this.totalPage = data.page.totalCount
  190. } else {
  191. this.dataList = []
  192. this.totalPage = 0
  193. this.$confirm(`查询养殖员信息失败`, '提示', {
  194. confirmButtonText: '确定',
  195. cancelButtonText: '取消',
  196. type: 'warning'
  197. }).then(() => {
  198. return
  199. }).catch(() => {})
  200. }
  201. this.dataListLoading = false
  202. })
  203. },
  204. // 每页数
  205. sizeChangeHandle (val) {
  206. this.pageSize = val
  207. this.pageIndex = 1
  208. this.getDataList()
  209. },
  210. // 当前页
  211. currentChangeHandle (val) {
  212. this.pageIndex = val
  213. this.getDataList()
  214. },
  215. // 新增 or 修改谱系信息
  216. addOrUpdateHandle (row) {
  217. // 显示谱系新增 or 修改面板
  218. this.visible = true
  219. if (row) {
  220. this.form = row
  221. }
  222. },
  223. // 选择n个养殖员
  224. selectionChangeHandle (val) {
  225. this.selectionDataList = []
  226. val.forEach(item => {
  227. this.selectionDataList.push(item.id)
  228. });
  229. },
  230. // 删除n个养殖员
  231. deleteHandle (id) {
  232. this.$confirm(`确定删除养殖员信息?`, '提示', {
  233. confirmButtonText: '确定',
  234. cancelButtonText: '取消',
  235. type: 'warning'
  236. }).then(() => {
  237. // 删除操作
  238. if (id) {
  239. this.selectionDataList.push(id)
  240. }
  241. if (this.selectionDataList.length <= 0) {
  242. return
  243. }
  244. this.$http({
  245. url: this.$http.adornUrl('/management/employee/delete'),
  246. method: 'post',
  247. data: this.$http.adornData(this.selectionDataList, false)
  248. }).then(result => {
  249. if (result.data.code === 0) {
  250. this.$message({
  251. message: '成功删除养殖员信息',
  252. type: 'success',
  253. duration: 1000
  254. })
  255. } else {
  256. this.$message.error('删除养殖员信息失败');
  257. }
  258. this.resetForm()
  259. this.selectionDataList = []
  260. })
  261. }).catch(() => {})
  262. },
  263. formSubmit () {
  264. if (this.form.id) {
  265. // 修改
  266. if (this.confirmInput()) {
  267. // 检查入场时间、离开场时间
  268. if (!this.confirmJobStatus()) {
  269. return
  270. }
  271. // 进行修改操作
  272. this.$http({
  273. url: this.$http.adornUrl('/management/employee/update'),
  274. method: 'post',
  275. data: this.$http.adornData({
  276. id: this.form.id,
  277. position: this.form.position,
  278. approachTime: this.form.approachTime,
  279. departureTime: this.form.departureTime,
  280. jobStatus: this.form.jobStatus
  281. })
  282. }).then(result => {
  283. if (result.data.code === 0) {
  284. this.resetForm();
  285. this.visible = false;
  286. this.$message({
  287. message: '成功修改养殖员信息',
  288. type: 'success',
  289. duration: 1000
  290. })
  291. } else {
  292. this.$message.error('修改养殖员信息失败');
  293. }
  294. })
  295. } else {
  296. // 请输入完整
  297. this.$confirm(`请输入完整`, '提示', {
  298. confirmButtonText: '确定',
  299. cancelButtonText: '取消',
  300. type: 'warning'
  301. }).then(() => {
  302. return
  303. }).catch(() => {})
  304. }
  305. } else {
  306. // 新增
  307. if (this.confirmInput(1)) {
  308. // 检查入场时间、立场时间、当前在岗
  309. if (!this.confirmJobStatus()) {
  310. return
  311. }
  312. // 进行新增操作
  313. this.$http({
  314. url: this.$http.adornUrl('/management/employee/save'),
  315. method: 'post',
  316. data: this.$http.adornData({
  317. name: this.form.name,
  318. position: this.form.position,
  319. approachTime: this.form.approachTime,
  320. departureTime: this.form.departureTime,
  321. jobStatus: this.form.jobStatus
  322. })
  323. }).then(result => {
  324. if (result.data.code === 0) {
  325. this.resetForm();
  326. this.visible = false;
  327. this.$message({
  328. message: '成功添加养殖员信息',
  329. type: 'success',
  330. duration: 1000
  331. })
  332. } else {
  333. this.$message.error('添加养殖员信息失败');
  334. }
  335. })
  336. } else {
  337. // 请输入完整
  338. this.$confirm(`请输入完整`, '提示', {
  339. confirmButtonText: '确定',
  340. cancelButtonText: '取消',
  341. type: 'warning'
  342. }).then(() => {
  343. return
  344. }).catch(() => {})
  345. }
  346. }
  347. },
  348. // 判断新增/修改时是否输入完整
  349. confirmInput (val) {
  350. val && (delete this.form.id, delete this.form.deleted, delete this.form.gmtCreate, delete this.form.gmtModified)
  351. for (let i in this.form) {
  352. if (!this.form[i].toString()) {
  353. return false
  354. }
  355. }
  356. return true
  357. },
  358. // 清空form
  359. resetForm () {
  360. for (let i in this.form) {
  361. this.form[i] = ''
  362. }
  363. this.getDataList()
  364. },
  365. // 取消
  366. cancel () {
  367. this.visible = false
  368. this.resetForm()
  369. },
  370. // 判断当前在岗是否正确
  371. getJobStatus () {
  372. let start = new Date(this.form.approachTime)
  373. let end = new Date(this.form.departureTime)
  374. if (start <= end) {
  375. return true
  376. }
  377. return false
  378. },
  379. // 判断当前在岗与入场时间、离场时间是否有冲突
  380. confirmJobStatus () {
  381. if (this.getJobStatus()) {
  382. return true
  383. }
  384. this.$confirm(`请检查入场时间与离场时间`, '提示', {
  385. confirmButtonText: '确定',
  386. cancelButtonText: '取消',
  387. type: 'warning'
  388. }).then(() => {
  389. // return false
  390. console.log('新增养殖员有误');
  391. }).catch(() => {})
  392. return false
  393. }
  394. }
  395. }
  396. </script>
  397. <style scoped>
  398. </style>