Edit.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <el-dialog
  3. :close-on-click-modal="false"
  4. :close-on-press-escape="false"
  5. :title="title"
  6. :append-to-body="true"
  7. :visible.sync="isVisible"
  8. width="500px"
  9. top="50px"
  10. >
  11. <el-form ref="form" :model="tenant" :rules="rules" label-position="right" label-width="130px">
  12. <el-form-item :label='$t("calssSchedule.form.deptUsers")+":"' prop="userList">
  13. <el-cascader
  14. v-model="tenant.userList"
  15. key="1"
  16. :options="applyList"
  17. :props="{ multiple: true, checkStrictly: true , emitPath: false, expandTrigger: 'click'}"
  18. :show-all-levels="false"
  19. filterable
  20. clearable
  21. :placeholder='$t("common.pleaseSelect")'
  22. style="width: 100%;"
  23. >
  24. </el-cascader>
  25. </el-form-item>
  26. <el-form-item :label='$t("calssSchedule.form.setDate")+":"' prop="dateList">
  27. <el-date-picker :picker-options="pickerOptions" v-model="tenant.dateList" type="dates" value-format="yyyy-MM-dd" :placeholder='$t("common.pleaseSelect")' style="width: 100%;"></el-date-picker>
  28. </el-form-item>
  29. <el-form-item :label='$t("calssSchedule.form.setClass")+":"' prop="frequencyId">
  30. <template>
  31. <el-select v-model="tenant.frequencyId" :placeholder='$t("common.pleaseSelect")' style="width: 100%;">
  32. <el-option
  33. v-for="item in classesList"
  34. :key="item.id"
  35. :label="item.name.data"
  36. :value="item.id">
  37. </el-option>
  38. </el-select>
  39. </template>
  40. </el-form-item>
  41. </el-form>
  42. <div slot="footer" class="dialog-footer">
  43. <el-button plain type="warning" @click="isVisible = false">{{ $t('common.cancel') }}</el-button>
  44. <el-button plain type="primary" :disabled="confirmDisabled" @click="submitForm">{{ $t('common.confirm') }}</el-button>
  45. </div>
  46. </el-dialog>
  47. </template>
  48. <script>
  49. // 【设置班表】-API
  50. import settingClassSchedulApi from "@/api/classScheduleMgr/settingClassSchedul"
  51. // 【班次管理】-API
  52. import classesMgrApi from "@/api/classScheduleMgr/classesMgr"
  53. // 【部门组织】-API
  54. import orgApi from "@/api/Org"
  55. export default {
  56. name: 'TenantEdit',
  57. props: {
  58. dialogVisible: {
  59. type: Boolean,
  60. default: false
  61. },
  62. title: {
  63. type: String,
  64. default: ''
  65. }
  66. },
  67. data () {
  68. return {
  69. pickerOptions: {
  70. disabledDate: (time) => {
  71. // return time.getTime() < Date.now() - 86400000;
  72. return time.getTime() < new Date(this.tenant.monthBeginDay).getTime() || time.getTime() > new Date(this.tenant.monthLastDay).getTime()
  73. },
  74. },
  75. type: 'add',
  76. tenant: this.initTenant(),
  77. screenWidth: 0,
  78. width: this.initWidth(),
  79. confirmDisabled: false,
  80. classesList: [], // 班次设置,下拉数据
  81. applyList: [],
  82. applyCheckbox: [], // 【更换班表-申请人】
  83. updateCheckbox: [], // 【更换班表-更换人】
  84. dicts:{
  85. NATION: {}
  86. },
  87. roles: [],
  88. rules: {
  89. userList: [
  90. { required: true, message: this.$t("rules.require"), trigger: 'change' }
  91. ],
  92. date: [
  93. { required: true, message: this.$t("rules.require"), trigger: 'change' }
  94. ],
  95. frequencyId: [
  96. { required: true, message: this.$t("rules.require"), trigger: 'change' }
  97. ]
  98. }
  99. }
  100. },
  101. // 实例已经在内存中创建好,此时data和methods已将ok,如果要操作data中的数据或是调用methods中的方法,最早只能在created中操作
  102. created() {
  103. // [部门人员]的获取
  104. // this.applyList = this.$constWKS.CASCADERLIST
  105. this.getDeptUser()
  106. // [设置班次]的获取
  107. this.getClassesList()
  108. },
  109. computed: {
  110. isVisible: {
  111. get () {
  112. return this.dialogVisible
  113. },
  114. set () {
  115. this.close()
  116. this.reset()
  117. }
  118. }
  119. },
  120. mounted () {
  121. window.onresize = () => {
  122. return (() => {
  123. this.width = this.initWidth()
  124. })()
  125. }
  126. },
  127. methods: {
  128. initTenant () {
  129. return {
  130. frequencyId: '',
  131. dateList: [],
  132. userList: [],
  133. monthBeginDay: '',
  134. monthLastDay: '',
  135. }
  136. },
  137. initWidth () {
  138. this.screenWidth = document.body.clientWidth
  139. if (this.screenWidth < 991) {
  140. return '90%'
  141. } else if (this.screenWidth < 1400) {
  142. return '45%'
  143. } else {
  144. return '800px'
  145. }
  146. },
  147. setTenant (val, dicts,monthBeginDay,monthLastDay) {
  148. if(val){
  149. this.tenant = { ...val }
  150. }
  151. this.tenant.monthBeginDay = monthBeginDay
  152. this.tenant.monthLastDay = monthLastDay
  153. // 字典表
  154. this.dicts = dicts
  155. },
  156. close () {
  157. this.$emit('close')
  158. },
  159. reset () {
  160. // 先清除校验,再清除表单,不然有奇怪的bug
  161. this.$refs.form.clearValidate()
  162. this.$refs.form.resetFields()
  163. this.tenant = this.initTenant()
  164. },
  165. submitForm () {
  166. //console.log("Form数据:", this.tenant)
  167. //return false
  168. this.$refs.form.validate((valid) => {
  169. if (valid) {
  170. this.confirmDisabled = true
  171. if (this.type === 'add') {
  172. this.save()
  173. } else {
  174. this.update()
  175. }
  176. } else {
  177. return false
  178. }
  179. })
  180. },
  181. save () {
  182. settingClassSchedulApi.setSchedule(this.tenant)
  183. .then((response) => {
  184. const res = response.data
  185. if (res.isSuccess) {
  186. this.isVisible = false
  187. this.$message({
  188. message: this.$t('tips.createSuccess'),
  189. type: 'success'
  190. })
  191. // 通知列表
  192. this.$emit("success");
  193. // 通知列表-并关闭弹出框
  194. this.$emit("close");
  195. }
  196. }).finally(() => {
  197. this.confirmDisabled = false
  198. return true
  199. })
  200. },
  201. update () {
  202. settingClassSchedulApi.update(this.tenant)
  203. .then((response) => {
  204. const res = response.data
  205. if (res.isSuccess) {
  206. this.isVisible = false
  207. this.$message({
  208. message: this.$t('tips.updateSuccess'),
  209. type: 'success'
  210. })
  211. // 通知列表
  212. this.$emit("success");
  213. // 通知列表-并关闭弹出框
  214. this.$emit("close");
  215. }
  216. }).finally(() => {
  217. this.confirmDisabled = false
  218. return true
  219. })
  220. },
  221. // 【更换班表】-列表数据
  222. applyClassList(flag, val){
  223. classesMgrApi.getListById({userId: ''}).then(res => {
  224. res = res.data
  225. console.log("【更换班表】-列表数据: ", res)
  226. if (res.isSuccess) {
  227. // 如果是【申请人-更换班表】
  228. if(flag){
  229. this.applyCheckbox = res.data
  230. }else{ // 如果是【更换人-更换班表】
  231. this.updateCheckbox = res.data
  232. }
  233. }
  234. })
  235. },
  236. // [设置班次]下拉的数据
  237. getClassesList(){
  238. classesMgrApi.getList({}).then(res => {
  239. res = res.data
  240. console.log("【设置班次】-列表数据: ", res)
  241. if (res.isSuccess) {
  242. this.classesList = res.data
  243. }
  244. })
  245. },
  246. // 【部门人员】-级联数据
  247. getDeptUser(){
  248. orgApi.getDeptUser({}).then(res => {
  249. res = res.data
  250. // console.log("【部门人员】-级联数据: ", res)
  251. if(res.isSuccess){
  252. this.applyList = res.data
  253. }
  254. })
  255. }
  256. }
  257. }
  258. </script>
  259. <style lang="scss" >
  260. .avatar-uploader .el-upload {
  261. border: 1px dashed #d9d9d9;
  262. border-radius: 6px;
  263. cursor: pointer;
  264. position: relative;
  265. overflow: hidden;
  266. }
  267. .avatar-uploader .el-upload:hover {
  268. border-color: #409eff;
  269. }
  270. .avatar-uploader-icon {
  271. font-size: 28px;
  272. color: #8c939d;
  273. width: 100px;
  274. height: 100px;
  275. line-height: 100px;
  276. text-align: center;
  277. }
  278. .avatar {
  279. width: 100px;
  280. height: 100px;
  281. display: block;
  282. }
  283. .checkUsed{
  284. display: inline-block;
  285. margin-left: 10px;
  286. color: #1890ff;
  287. }
  288. </style>