华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

435 lines
13 KiB

  1. <template>
  2. <div class="study-subject">
  3. <div class="subject-top">{{study.name}}</div>
  4. <div class="subject-study">
  5. <div class="study-info">{{$t('page.business.study.study.sn')}}<span>{{study.sn}}</span></div>
  6. <div class="study-info">{{$t('page.business.study.study.syfzr')}}<span>{{study.leaderName}}</span></div>
  7. <div class="study-info">{{$t('page.business.study.study.createDate')}}<span>{{study.createTime}}</span></div>
  8. </div>
  9. <div class="subject-operate">
  10. <div class="operate-img"></div>
  11. <div class="operate-left">{{$t('page.business.study.studyEnter.syxkxx')}}</div>
  12. <div class="operate-right">
  13. <i class="el-icon-edit operate-icon" @click="editSubject" v-if="operate && study.status<5 && (study.leader==userId || checkRole(['TFM']))"></i>
  14. </div>
  15. </div>
  16. <div class="subject-content">
  17. <div class="subject-item" :class="selectedSubjectId===item.id?'active':''" v-for="(item,index) in subjectList" :key="index" @click="changeSelectedSubject(item)">
  18. <div class="subject-item-name">{{item.deptName}}({{$i18n.locale === 'zh_CN'?item.leaderName:item.leaderNameEn}})</div>
  19. <div class="subject-item-add" v-if="operate && study.status<5 && item.leader==userId">
  20. <el-button type="primary" plain @click.stop="yq(item)">{{$t('page.business.study.studyEnter.yq')}}</el-button>
  21. </div>
  22. </div>
  23. </div>
  24. <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :title="infoDialog.title" :visible.sync="infoDialog.visible" width="800px" append-to-body>
  25. <el-table v-loading="infoDialog.loading" :data="infoDialog.list" height="500px">
  26. <el-table-column label="" type="index" width="50">
  27. <template slot-scope="scope">
  28. <el-checkbox v-model="scope.row.select"></el-checkbox>
  29. </template>
  30. </el-table-column>
  31. <el-table-column :label="$t('page.business.study.studyEnter.xk')" prop="deptName" align="center" />
  32. <el-table-column :label="$t('page.business.study.studyEnter.czfzr')" align="center">
  33. <template slot-scope="scope">
  34. <div class="subject-table-box">
  35. <div class="subject-table-left">
  36. <el-input v-if="$i18n.locale === 'zh_CN'" v-model="scope.row.leaderName" maxlength="100" readonly />
  37. <el-input v-else v-model="scope.row.leaderNameEn" maxlength="100" readonly />
  38. </div>
  39. <div class="subject-table-right">
  40. <el-button type="primary" plain @click="chooseLeader(scope.row)">{{$t('page.business.study.studyEnter.xzfzr')}}</el-button>
  41. </div>
  42. </div>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. <div slot="footer" class="dialog-footer">
  47. <el-button type="primary" @click="save">{{$t('form.saveConfirm')}}</el-button>
  48. <el-button @click="infoDialog.visible = false">{{$t('form.cancel')}}</el-button>
  49. </div>
  50. </el-dialog>
  51. <SelectDeptUserDialog ref="selectSubjectDeptUserDialog" @change="changeSubject" />
  52. <SelectDeptUserMultipleDialog ref="selectSubjectDeptUserMultipleDialog" @change="changeMember" />
  53. <Sign ref="subjectSignRef" @callback="doSign" />
  54. </div>
  55. </template>
  56. <script>
  57. import { checkPermi, checkRole } from "@/utils/permission";
  58. import {
  59. studySubject_listByStudyId,
  60. studySubject_getAllListByStudyId,
  61. studySubject_save
  62. } from '@/api/business/study/studySubject'
  63. import {
  64. studySubjectUser_getListByStudySubjectId,
  65. studySubjectUser_save
  66. } from '@/api/business/study/studySubjectUser'
  67. import SelectDeptUserDialog from '@/views/business/comps/select/SelectDeptUserDialog.vue';
  68. import SelectDeptUserMultipleDialog from '@/views/business/comps/select/SelectDeptUserMultipleDialog.vue';
  69. import Sign from './sign.vue'
  70. export default {
  71. name: 'StudySubject',
  72. props: {
  73. study:{
  74. type:Object,
  75. default:()=>{
  76. return {}
  77. },
  78. deep: true,
  79. },
  80. operate:{
  81. type:Boolean,
  82. default:false
  83. }
  84. },
  85. watch: {
  86. study: {
  87. immediate: true,
  88. handler(v) {
  89. this.getList()
  90. }
  91. },
  92. },
  93. components: {SelectDeptUserDialog,SelectDeptUserMultipleDialog,Sign},
  94. filters: {},
  95. data() {
  96. return {
  97. userId:this.$store.getters.id,
  98. subjectList:[],
  99. selectedSubjectId:'',
  100. infoDialog:{
  101. title:this.$t('page.business.study.studyEnter.xzxk'),
  102. visible:false,
  103. loading:false,
  104. list:[],
  105. subject:{
  106. leader:'',
  107. leaderName:'',
  108. leaderNameEn:'',
  109. },
  110. saveList:[],
  111. oldList:[]//之前选择的,没修改就不用签名
  112. },
  113. memberSubject:{},
  114. signType:'',
  115. memberList:[],
  116. memberOldList:[]//之前选择的,没修改就不用签名
  117. }
  118. },
  119. created() {},
  120. methods: {
  121. checkPermi,
  122. checkRole,
  123. getList(){
  124. if(this.study.id){
  125. this.selectedSubjectId = ''
  126. let selectedDeptId = ''
  127. studySubject_listByStudyId({studyId:this.study.id}).then(response => {
  128. this.subjectList = response.data;
  129. for(let i=0;i<this.subjectList.length;i++){
  130. let item = this.subjectList[i]
  131. if(item.leader==this.userId || (item.userIdList && item.userIdList.length>0 && item.userIdList.indexOf(this.userId)>-1)){
  132. this.selectedSubjectId = item.id
  133. selectedDeptId = item.deptId
  134. break
  135. }
  136. }
  137. if(this.selectedSubjectId === ''){
  138. this.selectedSubjectId = this.subjectList.length>0?this.subjectList[0].id:''
  139. selectedDeptId = this.subjectList.length>0?this.subjectList[0].deptId:''
  140. }
  141. this.$emit('change',this.selectedSubjectId,selectedDeptId)
  142. })
  143. }
  144. },
  145. changeSelectedSubject(item){
  146. this.selectedSubjectId = item.id
  147. this.$emit('change',this.selectedSubjectId,item.deptId)
  148. },
  149. editSubject(){
  150. this.infoDialog.list = []
  151. this.infoDialog.loading = true
  152. studySubject_getAllListByStudyId({studyId:this.study.id}).then(response => {
  153. this.infoDialog.list = response.data;
  154. this.infoDialog.visible = true;
  155. this.infoDialog.oldList = _.cloneDeep(_.filter(this.infoDialog.list, (o)=> { return o.select }))
  156. }).finally(()=>{
  157. this.infoDialog.loading = false;
  158. });
  159. },
  160. save(){
  161. let postList = _.filter(this.infoDialog.list, (o)=> { return o.select })
  162. if(postList.length>0){
  163. for(let i=0;i<postList.length;i++){
  164. let item = postList[i]
  165. if(!item.leader || !item.leaderName){
  166. this.$message.error(`${item.deptName}还没设置负责人`)
  167. return false
  168. }
  169. }
  170. }
  171. //判断是否有修改
  172. let isModify = false
  173. if(postList.length===this.infoDialog.oldList.length){
  174. if(postList.length>0){
  175. for(let i=0;i<postList.length;i++){
  176. let item = postList[i]
  177. let find = false
  178. for(let j=0;j<this.infoDialog.oldList.length;j++){
  179. let old = this.infoDialog.oldList[j]
  180. if(old.deptId==item.deptId && old.deptName==item.deptName && old.leader==item.leader && old.leaderName==item.leaderName){
  181. find = true
  182. break
  183. }
  184. }
  185. if(!find){
  186. isModify = true
  187. break
  188. }
  189. }
  190. }
  191. }else{
  192. isModify = true
  193. }
  194. if(!isModify){
  195. this.infoDialog.visible = false
  196. }else{
  197. this.infoDialog.saveList = postList
  198. this.$modal.loading()
  199. studySubject_save({
  200. studyId:this.study.id,
  201. subjectList:this.infoDialog.saveList,
  202. sign:{}
  203. }).then(() => {
  204. this.signType = 'save'
  205. this.$refs.subjectSignRef.show(this.$t('page.business.study.study.rybg'),this.$t('page.business.study.study.rybg'))
  206. }).catch(() => {
  207. }).finally(() => {
  208. this.$modal.closeLoading()
  209. })
  210. }
  211. },
  212. doSign(val){
  213. if(this.signType==='save'){
  214. this.doSave(val)
  215. }
  216. if(this.signType==='member'){
  217. this.doChangeMember(val)
  218. }
  219. },
  220. doSave(sign){
  221. this.$modal.loading()
  222. studySubject_save({
  223. studyId:this.study.id,
  224. subjectList:this.infoDialog.saveList,
  225. sign:sign
  226. }).then(() => {
  227. this.infoDialog.visible = false
  228. this.$refs.subjectSignRef.cancel()
  229. this.getList()
  230. }).finally(() => {
  231. this.$modal.closeLoading()
  232. })
  233. },
  234. chooseLeader(row){
  235. this.infoDialog.subject = row
  236. this.$refs.selectSubjectDeptUserDialog.show(this.infoDialog.subject.leader,this.infoDialog.subject.leaderName,this.infoDialog.subject.leaderNameEn)
  237. },
  238. changeSubject(val){
  239. this.infoDialog.subject.leader = val.id
  240. this.infoDialog.subject.leaderName = val.name
  241. this.infoDialog.subject.leaderNameEn = val.nameEn
  242. this.infoDialog.subject.select = true
  243. let index = _.findIndex(this.infoDialog.list,(item)=>{
  244. return item.deptId===this.infoDialog.subject.deptId
  245. })
  246. if(index>-1){
  247. this.infoDialog.list.splice(index,1,this.infoDialog.subject)
  248. }
  249. },
  250. yq(item){
  251. this.memberSubject = item
  252. studySubjectUser_getListByStudySubjectId({studySubjectId:item.id}).then(response => {
  253. let memberList = []
  254. for(let i=0;i<response.data.length;i++){
  255. memberList.push({
  256. id:response.data[i].userId,
  257. name:response.data[i].userName,
  258. nameEn:response.data[i].userNameEn,
  259. })
  260. }
  261. this.memberOldList = _.cloneDeep(memberList)
  262. this.$refs.selectSubjectDeptUserMultipleDialog.show(memberList)
  263. }).finally(()=>{
  264. });
  265. },
  266. changeMember(val){
  267. let postList = []
  268. if(val.length>0){
  269. for(let i=0;i<val.length;i++){
  270. let item = val[i]
  271. postList.push({
  272. userId:item.id,
  273. userName:item.name,
  274. userNameEn:item.nameEn,
  275. })
  276. }
  277. }
  278. //对比是否有修改
  279. let isModify = false
  280. if(postList.length===this.memberOldList.length){
  281. if(postList.length>0){
  282. for(let i=0;i<postList.length;i++){
  283. let item = postList[i]
  284. let find = false
  285. for(let j=0;j<this.memberOldList.length;j++){
  286. let old = this.memberOldList[j]
  287. if(old.id==item.userId && old.name==item.userName){
  288. find = true
  289. break
  290. }
  291. }
  292. if(!find){
  293. isModify = true
  294. break
  295. }
  296. }
  297. }
  298. }else{
  299. isModify = true
  300. }
  301. if(!isModify){
  302. this.$refs.selectSubjectDeptUserMultipleDialog.close()
  303. }else{
  304. this.memberList = postList
  305. studySubjectUser_save({
  306. studySubjectId:this.memberSubject.id,
  307. subjectUserList:this.memberList,
  308. sign:{}
  309. }).then(() => {
  310. this.$refs.selectSubjectDeptUserMultipleDialog.close()
  311. this.signType = 'member'
  312. this.$refs.subjectSignRef.show(this.$t('page.business.study.study.rybg'),this.$t('page.business.study.study.rybg'))
  313. }).catch((e) => {
  314. }).finally(() => {
  315. })
  316. }
  317. },
  318. doChangeMember(sign){
  319. this.$modal.loading()
  320. studySubjectUser_save({
  321. studySubjectId:this.memberSubject.id,
  322. subjectUserList:this.memberList,
  323. sign:sign
  324. }).then(() => {
  325. this.$refs.subjectSignRef.cancel()
  326. }).finally(() => {
  327. this.$modal.closeLoading()
  328. })
  329. },
  330. }
  331. }
  332. </script>
  333. <style lang="scss" scoped>
  334. .study-subject {
  335. .subject-top {
  336. background: #f0f7ff;
  337. border-top-left-radius: 3px;
  338. border-top-right-radius: 3px;
  339. border-top: 3px solid #409eff;
  340. padding: 20px 0;
  341. text-align: center;
  342. color: #409eff;
  343. font-weight: bold;
  344. }
  345. .subject-study{
  346. background: #fafcff;
  347. padding: 20px;
  348. color: #666666;
  349. position: relative;
  350. .study-info{
  351. margin-bottom: 20px;
  352. span{
  353. color: #777;
  354. }
  355. &:last-child{
  356. margin-bottom: 0;
  357. }
  358. }
  359. }
  360. .subject-operate{
  361. margin: 20px 0;
  362. display: flex;
  363. flex-direction: row;
  364. align-items: center;
  365. .operate-img{
  366. flex-shrink: 0;
  367. height: 15px;
  368. background: #3178ff;
  369. width: 3px;
  370. }
  371. .operate-left{
  372. flex-shrink: 0;
  373. font-weight: bold;
  374. padding-left: 10px;
  375. }
  376. .operate-right{
  377. flex-grow: 1;
  378. text-align: right;
  379. .operate-icon{
  380. cursor: pointer;
  381. }
  382. }
  383. }
  384. .subject-content{
  385. .subject-item{
  386. margin-bottom: 10px;
  387. padding: 10px;
  388. display: flex;
  389. flex-direction: row;
  390. align-items: center;
  391. justify-content: space-between;
  392. background: #f9fafc;
  393. border-radius: 5px;
  394. cursor: pointer;
  395. &.active{
  396. border: 1px solid #47a1ff;
  397. }
  398. .subject-item-name{
  399. color: #777;
  400. }
  401. .subject-item-add{
  402. }
  403. }
  404. }
  405. }
  406. .subject-table-box{
  407. display: flex;
  408. flex-direction: row;
  409. align-items: center;
  410. .subject-table-left{
  411. flex-shrink: 0;
  412. width: 60%;
  413. }
  414. .subject-table-right{
  415. flex-grow: 1;
  416. margin-left: 5px;
  417. }
  418. }
  419. </style>