index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <d2-container>
  3. <template slot="header"
  4. style="padding: 5px;">
  5. <el-form :model="dutyDetail"
  6. label-width="100px">
  7. <el-row :gutter="20">
  8. <el-col :span="8">
  9. <el-form-item label="标题"
  10. label-width="120px">
  11. {{dutyDetail.Title}}
  12. </el-form-item>
  13. </el-col>
  14. <el-col :span="8">
  15. <el-form-item label="学年"
  16. label-width="120px">
  17. {{dutyDetail.Year}}年
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="8">
  21. <el-form-item label="学期"
  22. label-width="120px">
  23. {{this.termName}}
  24. </el-form-item>
  25. </el-col>
  26. <el-col :span="8">
  27. <el-form-item label="值班人员"
  28. size="mini"
  29. label-width="120px">
  30. <el-tag @click="personClick(item.ItemValue)"
  31. v-for="item in PeopleList"
  32. :key="item.ItemValue"
  33. :label="item.ItemValue">{{item.ItemName}}</el-tag>
  34. </el-form-item>
  35. </el-col>
  36. <el-col :span="8">
  37. <el-form-item label="地点"
  38. size="mini"
  39. label-width="120px">
  40. <el-checkbox-group v-model="selectLocal">
  41. <el-checkbox v-for="(item,index) in LocalList"
  42. :label="item.ItemValue"
  43. @change="getDetailData(index,item)"
  44. :key="item.ItemValue">{{item.ItemName}}</el-checkbox>
  45. </el-checkbox-group>
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="8">
  49. <el-form-item label="值班时间"
  50. size="mini"
  51. label-width="120px">
  52. <el-checkbox-group v-model="selectTime">
  53. <el-checkbox v-for="item in TimeList"
  54. :label="item.ItemValue"
  55. :key="item.ItemValue">{{item.ItemName}}</el-checkbox>
  56. </el-checkbox-group>
  57. </el-form-item>
  58. </el-col>
  59. </el-row>
  60. <el-button size="mini"
  61. @click="addList()"
  62. type="success"
  63. style="margin-right:6px">生成表格</el-button>
  64. <el-button size="mini"
  65. type="primary"
  66. style="margin-left:10px"
  67. @click="addDuytDetail()">保存</el-button>
  68. <el-button size="mini"
  69. type="warning"
  70. style="margin-right:6px"
  71. @click="closePage()">关闭</el-button>
  72. </el-form>
  73. </template>
  74. <el-table :data="list"
  75. border
  76. fit
  77. tooltip-effect="dark"
  78. style="width: 100%"
  79. height="100%"
  80. @cell-click="cellclick"
  81. @header-click="headclick"
  82. :cell-class-name="cellBg"
  83. :key="refresh">
  84. <el-table-column fit
  85. prop="Local"
  86. min-width="160px"
  87. label="地点"
  88. align="center"
  89. show-overflow-tooltip
  90. :formatter="formatLocal"></el-table-column>
  91. <el-table-column prop="Time"
  92. label="时间段"
  93. align="center"
  94. min-width="120px"
  95. show-overflow-tooltip
  96. :formatter="formatTime"></el-table-column>
  97. <el-table-column prop="Monday"
  98. label="周一"
  99. align="center"
  100. min-width="120px"
  101. show-overflow-tooltip
  102. :formatter="formatPerson"></el-table-column>
  103. <el-table-column prop="Tuesday"
  104. label="周二"
  105. align="center"
  106. min-width="120px"
  107. show-overflow-tooltip
  108. :formatter="formatPerson"></el-table-column>
  109. <el-table-column prop="Wednesday"
  110. label="周三"
  111. align="center"
  112. min-width="120px"
  113. show-overflow-tooltip
  114. :formatter="formatPerson"></el-table-column>
  115. <el-table-column prop="Thursday"
  116. label="周四"
  117. align="center"
  118. min-width="120px"
  119. show-overflow-tooltip
  120. :formatter="formatPerson"></el-table-column>
  121. <el-table-column prop="Friday"
  122. label="周五"
  123. align="center"
  124. min-width="120px"
  125. show-overflow-tooltip
  126. :formatter="formatPerson"></el-table-column>
  127. <el-table-column prop="Saturday"
  128. label="周六"
  129. align="center"
  130. min-width="120px"
  131. show-overflow-tooltip
  132. :formatter="formatPerson"></el-table-column>
  133. <el-table-column prop="Sunday"
  134. label="周日"
  135. align="center"
  136. min-width="120px"
  137. show-overflow-tooltip
  138. :formatter="formatPerson"></el-table-column>
  139. <el-table-column label="操作"
  140. width="80px"
  141. align="center">
  142. <template slot-scope="scope">
  143. <el-button size="mini"
  144. type="danger"
  145. title="删除"
  146. @click="deleteRow(scope.$index,list)"
  147. style="margin-left:3px;"
  148. icon="el-icon-delete"
  149. circle></el-button>
  150. </template>
  151. </el-table-column>
  152. </el-table>
  153. </d2-container>
  154. </template>
  155. <script>
  156. // 总列数
  157. import { mapState, mapActions } from 'vuex'
  158. import DutyApi from '@/api/duty'
  159. import itemDetailApi from '@/api/sysadmin/itemdetail'
  160. const columnNum = 9
  161. // 固定列数
  162. const fixRowHeadNum = 2
  163. // todo 欠优化 列属性对应
  164. const columnProperty = [
  165. 'Local',
  166. 'Time',
  167. 'Monday',
  168. 'Tuesday',
  169. 'Wednesday',
  170. 'Thursday',
  171. 'Friday',
  172. 'Saturday',
  173. 'Sunday'
  174. ]
  175. export default {
  176. name: 'dutyEdit',
  177. data () {
  178. return {
  179. LocalList: [],
  180. PeopleList: [],
  181. TimeList: [],
  182. termList: [],
  183. termName: '',
  184. selectLocal: [],
  185. selectTime: [],
  186. dutyDetail: {
  187. Id: -1,
  188. Year: -1,
  189. Term: -1
  190. },
  191. year: '',
  192. years: [],
  193. dialogvisible: false,
  194. // 刷新标志 刷新表格样式
  195. refresh: 123,
  196. // 已选列表
  197. selectcell: new Map(),
  198. // 数据列表
  199. list: []
  200. }
  201. },
  202. computed: {
  203. ...mapState('d2admin/page', [
  204. 'opened',
  205. 'current' // 用户获取当前页面的地址,用于关闭
  206. ])
  207. },
  208. mounted () {
  209. this.getLocal()
  210. this.getPeople()
  211. this.getDutyTime()
  212. let _this = this
  213. _this.dutyDetail = _this.$route.query.duty
  214. _this.termList = _this.$route.query.term
  215. this.getTerm()
  216. this.getDetailData()
  217. },
  218. methods: {
  219. // 初始化单选框
  220. selectCheckBox () {
  221. let selectLocal = new Map()
  222. let selectTime = new Map()
  223. for (var i = 0; i < this.list.length; i++) {
  224. if (selectLocal.get(this.list[i].Local + '') !== true) {
  225. this.selectLocal.push(this.list[i].Local + '')
  226. }
  227. if (selectTime.get(this.list[i].Time + '') !== true) {
  228. this.selectTime.push(this.list[i].Time + '')
  229. }
  230. selectLocal.set(this.list[i].Local + '', true)
  231. selectTime.set(this.list[i].Time + '', true)
  232. }
  233. },
  234. // 获取值班子表表格
  235. getDetailData () {
  236. let _this = this
  237. DutyApi.getDetailByDutyId({
  238. DutyId: _this.dutyDetail.Id
  239. }).then(res => {
  240. if (res.length > 0) {
  241. _this.list = res
  242. _this.selectCheckBox()
  243. }
  244. })
  245. },
  246. // 新增表格
  247. addList () {
  248. if (this.selectLocal == 0 && this.selectTime.length == 0) {
  249. return
  250. }
  251. this.list = []
  252. this.selectcell = new Map()
  253. let _this = this
  254. this.selectLocal.forEach(function (value, key) {
  255. _this.selectTime.forEach(function (valuee, keyy) {
  256. _this.list.push({
  257. DutyId: _this.dutyDetail.Id,
  258. Local: value,
  259. Time: valuee,
  260. Monday: 0,
  261. Tuesday: 0,
  262. Wednesday: 0,
  263. Thursday: 0,
  264. Friday: 0,
  265. Saturday: 0,
  266. Sunday: 0
  267. })
  268. })
  269. })
  270. },
  271. // 保存值班子表信息
  272. addDuytDetail () {
  273. let _this = this
  274. if (this.dutyDetail.Id) {
  275. DutyApi.Saves({ DataList: this.list, DutyId: this.dutyDetail.Id })
  276. .then(res => {
  277. // console.log(res, 11111111111)
  278. // if (res.code == 0) {
  279. // _this.$message({
  280. // type: 'success',
  281. // message: res.message
  282. // })
  283. // } else {
  284. // _this.$message({
  285. // type: 'warning',
  286. // message: res.message
  287. // })
  288. // }
  289. })
  290. .catch(err => {
  291. // handle error
  292. console.error(err)
  293. })
  294. } else {
  295. console.log('error submit!!')
  296. return false
  297. }
  298. },
  299. // 删除一行
  300. deleteRow (index, rows) {
  301. rows.splice(index, 1)
  302. },
  303. // 获取字典表地点
  304. getLocal () {
  305. let _this = this
  306. itemDetailApi.getItemDetailByItemCode({ ItemCode: 'Local' })
  307. .then(res => {
  308. _this.LocalList = res
  309. })
  310. .catch(err => {
  311. console.error(err)
  312. })
  313. },
  314. // 多选框回显
  315. change (index, item) {
  316. },
  317. // 获取字典表值班人员
  318. getPeople () {
  319. let _this = this
  320. itemDetailApi.getItemDetailByItemCode({ ItemCode: 'People' })
  321. .then(res => {
  322. _this.PeopleList = res
  323. })
  324. .catch(err => {
  325. console.error(err)
  326. })
  327. },
  328. // 获取字典表课程时间段
  329. getDutyTime () {
  330. let _this = this
  331. itemDetailApi.getItemDetailByItemCode({ ItemCode: 'DutyTime' })
  332. .then(res => {
  333. _this.TimeList = res
  334. })
  335. .catch(err => {
  336. console.error(err)
  337. })
  338. },
  339. // 单元格、行选中
  340. cellclick (row, column, cell, event) {
  341. // 第3列开始可以选中
  342. // 单击单元格选中
  343. // 取消操作行选中
  344. if (cell.cellIndex >= columnNum) {
  345. return
  346. }
  347. if (cell.cellIndex >= fixRowHeadNum) {
  348. if (this.selectcell.get(row.Local + '_' + row.Time + '_' + column.property)) {
  349. this.selectcell.set(row.Local + '_' + row.Time + '_' + column.property, false)
  350. } else {
  351. this.selectcell.set(row.Local + '_' + row.Time + '_' + column.property, this.list[row.index])
  352. }
  353. }
  354. // 第三列之前选中整行
  355. // 行选中
  356. var currentcolumnindex = column.index
  357. if (cell.cellIndex < fixRowHeadNum) {
  358. for (var i = cell.cellIndex; i < columnNum - 1; i++) {
  359. currentcolumnindex = currentcolumnindex + 1
  360. var nextSibling = cell.nextSibling
  361. cell = nextSibling
  362. if (i >= fixRowHeadNum - 1) {
  363. if (this.selectcell.get(row.Local + '_' + row.Time + '_' + columnProperty[currentcolumnindex])) {
  364. this.selectcell.set(row.Local + '_' + row.Time + '_' + columnProperty[currentcolumnindex], false)
  365. } else {
  366. this.selectcell.set(row.Local + '_' + row.Time + '_' + columnProperty[currentcolumnindex], this.list[row.index])
  367. }
  368. }
  369. }
  370. }
  371. this.refresh = Math.random()
  372. },
  373. // 列选中
  374. headclick (column, event) {
  375. // 判断是否为可选列
  376. // 取消操作列选中
  377. if (column.index >= columnNum) {
  378. return
  379. }
  380. if (column.index > fixRowHeadNum - 1) {
  381. for (var i = 0; i < this.list.length; i++) {
  382. if (this.selectcell.get(this.list[i].Local + '_' + this.list[i].Time + '_' + column.property)) {
  383. this.selectcell.set(this.list[i].Local + '_' + this.list[i].Time + '_' + column.property, false)
  384. } else {
  385. this.selectcell.set(this.list[i].Local + '_' + this.list[i].Time + '_' + column.property, this.list[i])
  386. }
  387. }
  388. }
  389. this.refresh = Math.random()
  390. },
  391. // 选择值班人员
  392. personClick (person) {
  393. this.selectcell.forEach(function (value, key) {
  394. if (value) {
  395. var property = key.split('_')
  396. value[property[2]] = person
  397. }
  398. })
  399. this.selectcell = new Map()
  400. },
  401. // 更新背景
  402. cellBg ({ row, column, rowIndex, columnIndex }) {
  403. row.index = rowIndex
  404. column.index = columnIndex
  405. let _this = this
  406. // 注意这里是解构
  407. // 利用单元格的 className 的回调方法,给行列索引赋值
  408. if (_this.selectcell.get(row.Local + '_' + row.Time + '_' + column.property)) {
  409. return 'selectedCell'
  410. }
  411. },
  412. // 匹配学期
  413. formatTerm (row, column) {
  414. for (var i = 0; i < this.termList.length; i++) {
  415. if (parseInt(this.termList[i].ItemValue) === parseInt(row.Term)) {
  416. return this.termList[i].ItemName
  417. }
  418. }
  419. },
  420. // 获取学期名称
  421. getTerm () {
  422. let termName = ''
  423. let _this = this
  424. _this.termList.forEach(function (value, key) {
  425. if (_this.dutyDetail.Term == value.ItemValue) {
  426. _this.termName = value.ItemName
  427. }
  428. })
  429. },
  430. formatPerson (row, column, cellValue, index) {
  431. let label = '休息'
  432. for (var i = 0; i < this.PeopleList.length; i++) {
  433. if (this.PeopleList[i].ItemValue == cellValue) {
  434. return this.PeopleList[i].ItemName
  435. }
  436. }
  437. return label
  438. },
  439. formatLocal (row, column, cellValue, index) {
  440. for (var i = 0; i < this.LocalList.length; i++) {
  441. if (this.LocalList[i].ItemValue == cellValue) {
  442. return this.LocalList[i].ItemName
  443. }
  444. }
  445. },
  446. formatTime (row, column, cellValue, index) {
  447. for (var i = 0; i < this.TimeList.length; i++) {
  448. if (this.TimeList[i].ItemValue == cellValue) {
  449. return this.TimeList[i].ItemName
  450. }
  451. }
  452. },
  453. // 关闭页面
  454. ...mapActions('d2admin/page', [
  455. 'close'
  456. ]),
  457. // 关闭
  458. closePage () {
  459. let tagName = this.current
  460. this.close({ tagName })
  461. }
  462. }
  463. }
  464. </script>
  465. <style>
  466. .selectedCell {
  467. background-color: green !important;
  468. color: white;
  469. }
  470. </style>