create.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form" inline>
  4. <el-row>
  5. <el-col :span="6">
  6. <el-form-item
  7. label="分部"
  8. prop="organId"
  9. :rules="[{required: true, message: '请选择分部'}]"
  10. >
  11. <el-select
  12. clearable
  13. filterable
  14. v-model="form.organId"
  15. :disabled="!isCreate"
  16. placeholder="请选择分部"
  17. >
  18. <el-option v-for="(item,index) in selects.branchs"
  19. :key="index"
  20. :label="item.name"
  21. :value="item.id"></el-option>
  22. </el-select>
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="6">
  26. <el-form-item
  27. label="工作周期"
  28. prop="month"
  29. :rules="[{required: true, message: '请选择工作周期'}]"
  30. >
  31. <el-date-picker
  32. v-model="form.month"
  33. :disabled="!isCreate"
  34. type="month"
  35. placeholder="请选择工作周期">
  36. </el-date-picker>
  37. </el-form-item>
  38. </el-col>
  39. </el-row>
  40. <el-row class="group" v-for="(groupItem, groupIndex) in form.group" :key="groupIndex">
  41. <el-col :span="6">
  42. <el-form-item
  43. label="乐团主管"
  44. :prop="`group.${groupIndex}.userId`"
  45. :rules="[{required: true, message: '请选择乐团主管'}]"
  46. >
  47. <el-select
  48. clearable
  49. filterable
  50. v-model="groupItem.userId"
  51. :disabled="!isCreate"
  52. placeholder="请选择乐团主管"
  53. >
  54. <el-option v-for="(item,index) in technicians"
  55. :key="index"
  56. :label="item.realName"
  57. :disabled="form.group.map(m => m.userId).includes(item.userId)"
  58. :value="item.userId"></el-option>
  59. </el-select>
  60. </el-form-item>
  61. </el-col>
  62. <template v-for="(matterItem, matterIndex) in groupItem.matter">
  63. <el-col :offset="matterIndex === 0 ? 0 : 6" :span="6" :key="groupIndex + '-' + matterIndex + '1'">
  64. <el-form-item
  65. :label="'任务事项' + (matterIndex + 1)"
  66. :prop="`group.${groupIndex}.matter.${matterIndex}.item`"
  67. >
  68. <el-select
  69. clearable
  70. filterable
  71. v-model="matterItem.item"
  72. :disabled="!isCreate && !!matterItem.item"
  73. placeholder="请选择任务事项"
  74. >
  75. <el-option v-for="(item,index) in matterTypesOptions"
  76. :key="index"
  77. :label="item.label"
  78. :disabled="groupItem.matter.map(m => m.item).includes(item.value)"
  79. :value="item.value"></el-option>
  80. </el-select>
  81. </el-form-item>
  82. </el-col>
  83. <el-col :span="6" :key="groupIndex + '-' + matterIndex + '2'">
  84. <el-form-item
  85. :label="'任务次数' + (matterIndex + 1)"
  86. :prop="`group.${groupIndex}.matter.${matterIndex}.times`"
  87. >
  88. <el-input clearable v-model="matterItem.times" placeholder="请输入次数" />
  89. </el-form-item>
  90. </el-col>
  91. <el-col :span="6" :key="groupIndex + '-' + matterIndex + '3'">
  92. <div class="ctrl">
  93. <span>
  94. <el-tooltip content="添加任务" placement="top" :open-delay=".5">
  95. <el-button
  96. icon="el-icon-plus"
  97. @click="createMatter(groupItem.matter)"
  98. circle
  99. ></el-button>
  100. </el-tooltip>
  101. <el-tooltip content="删除任务" placement="top" :open-delay=".5">
  102. <el-button
  103. icon="el-icon-minus"
  104. circle
  105. @click="removeMatter(groupItem.matter, matterIndex)"
  106. :disabled="groupItem.matter.length <= 1"
  107. ></el-button>
  108. </el-tooltip>
  109. </span>
  110. <el-tooltip v-if="isCreate" content="删除乐团主管" placement="top" :open-delay=".5">
  111. <el-button
  112. icon="el-icon-delete"
  113. circle
  114. type="danger"
  115. v-if="matterIndex === 0"
  116. @click="removeGroup(form.group, groupIndex)"
  117. :disabled="form.group.length <= 1"
  118. ></el-button>
  119. </el-tooltip>
  120. </div>
  121. </el-col>
  122. </template>
  123. </el-row>
  124. <el-button v-if="isCreate" @click="createGroup" plain block style="width: 100%">添加乐团主管</el-button>
  125. </el-form>
  126. <div slot="footer" style="text-align: right;margin-top: 20px;">
  127. <el-button @click="$emit('close')">取消</el-button>
  128. <el-button type="primary" @click="submit">确认</el-button>
  129. </div>
  130. </div>
  131. </template>
  132. <script>
  133. import { matterTypes } from '@/views/main/constant'
  134. import { objectToOptions } from '@/utils'
  135. import { createRandom } from '@/helpers/uuidv4'
  136. import { inspectionAdd, inspectionGetInfo, inspectionUpdate, getMusicGroupEduTeacher } from '@/views/main/api'
  137. import { getOrganRole } from '@/api/buildTeam'
  138. const emptyMatter = {
  139. item: '',
  140. times: ''
  141. }
  142. export default {
  143. props: ['id'],
  144. data() {
  145. return {
  146. form: {
  147. organId: '',
  148. group: [{
  149. _uuid: createRandom(),
  150. userId: '',
  151. matter: [{...emptyMatter}]
  152. }]
  153. },
  154. technicians: []
  155. }
  156. },
  157. computed: {
  158. matterTypesOptions() {
  159. return objectToOptions(matterTypes)
  160. },
  161. isCreate() {
  162. return !this.id
  163. },
  164. },
  165. watch: {
  166. async 'form.organId'() {
  167. if (this.form.organId) {
  168. try {
  169. const res = await getOrganRole({
  170. organId: this.form.organId,
  171. rows: 999
  172. })
  173. this.technicians = res.data?.EDUCATION || []
  174. if (this.isCreate) {
  175. this.$set(this.form, 'group', this.form.group.map(item => ({...item, userId: ''})))
  176. }
  177. } catch (error) {}
  178. }
  179. }
  180. },
  181. async mounted() {
  182. try {
  183. const res = await inspectionGetInfo({
  184. id: this.id
  185. })
  186. this.form = {
  187. ...this.form,
  188. organId: res.data.organId,
  189. month: res.data.month,
  190. group: [{
  191. _uuid: createRandom(),
  192. userId: res.data.userId,
  193. matter: res.data.inspectionItems.map(item => ({item: item.item, times: item.times}))
  194. }]
  195. }
  196. } catch (error) {}
  197. },
  198. methods: {
  199. createGroup() {
  200. this.form.group.push({
  201. userId: '',
  202. matter: [{...emptyMatter}]
  203. })
  204. },
  205. createMatter(matter) {
  206. matter.push({...emptyMatter})
  207. },
  208. removeMatter(matter, index) {
  209. matter.splice(index, 1)
  210. },
  211. async removeGroup(group, index) {
  212. try {
  213. await this.$confirm('是否确认删除此乐团主管?', '提示', {
  214. type: 'warning'
  215. })
  216. group.splice(index, 1)
  217. } catch (error) {}
  218. },
  219. async submit() {
  220. try {
  221. this.$refs.form.validate(async valid => {
  222. if (valid) {
  223. const data = this.form.group.map(item => ({
  224. organId: this.form.organId,
  225. month: this.form.month,
  226. userId: item.userId,
  227. inspectionItems: item.matter.map(m => ({
  228. ...m,
  229. organId: this.form.organId,
  230. month: this.form.month,
  231. }))
  232. }))
  233. if (this.isCreate) {
  234. await inspectionAdd(data)
  235. this.$message.success('创建成功')
  236. } else {
  237. await inspectionUpdate({
  238. ...data[0],
  239. id: this.id,
  240. })
  241. this.$message.success('修改成功')
  242. }
  243. this.$emit('close')
  244. this.$emit('submited')
  245. }
  246. })
  247. } catch (error) {}
  248. }
  249. }
  250. }
  251. </script>
  252. <style lang="less" scoped>
  253. .group{
  254. background-color: rgba(0, 0, 0, 0.05);
  255. padding: 10px;
  256. border-radius: 3px;
  257. margin-bottom: 10px;
  258. }
  259. .ctrl{
  260. margin-top: 45px;
  261. display: flex;
  262. justify-content: space-between;
  263. i{
  264. font-size: 24px;
  265. }
  266. }
  267. </style>