华西海圻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.

373 lines
11 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.name')}}<span>{{study.name}}</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.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 && 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">
  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. },
  112. memberSubject:{},
  113. signType:'',
  114. memberList:[]
  115. }
  116. },
  117. created() {},
  118. methods: {
  119. checkPermi,
  120. checkRole,
  121. getList(){
  122. if(this.study.id){
  123. this.selectedSubjectId = ''
  124. studySubject_listByStudyId({studyId:this.study.id}).then(response => {
  125. this.subjectList = response.data;
  126. for(let i=0;i<this.subjectList.length;i++){
  127. let item = this.subjectList[i]
  128. if(item.leader==this.userId || (item.userIdList && item.userIdList.length>0 && item.userIdList.indexOf(this.userId)>-1)){
  129. this.selectedSubjectId = item.id
  130. break
  131. }
  132. }
  133. if(this.selectedSubjectId === ''){
  134. this.selectedSubjectId = this.subjectList.length>0?this.subjectList[0].id:''
  135. }
  136. this.$emit('change',this.selectedSubjectId)
  137. })
  138. }
  139. },
  140. changeSelectedSubject(item){
  141. this.selectedSubjectId = item.id
  142. this.$emit('change',this.selectedSubjectId)
  143. },
  144. editSubject(){
  145. this.infoDialog.list = []
  146. this.infoDialog.loading = true
  147. studySubject_getAllListByStudyId({studyId:this.study.id}).then(response => {
  148. this.infoDialog.list = response.data;
  149. this.infoDialog.visible = true;
  150. }).finally(()=>{
  151. this.infoDialog.loading = false;
  152. });
  153. },
  154. save(){
  155. let postList = _.filter(this.infoDialog.list, (o)=> { return o.select })
  156. if(postList.length>0){
  157. for(let i=0;i<postList.length;i++){
  158. let item = postList[i]
  159. if(!item.leader || !item.leaderName){
  160. this.$message.error(`${item.deptName}还没设置负责人`)
  161. return false
  162. }
  163. }
  164. }
  165. this.infoDialog.saveList = postList
  166. this.$modal.loading()
  167. studySubject_save({
  168. studyId:this.study.id,
  169. subjectList:this.infoDialog.saveList,
  170. sign:{}
  171. }).then(() => {
  172. this.signType = 'save'
  173. this.$refs.subjectSignRef.show(this.$t('page.business.study.study.rybg'),this.$t('page.business.study.study.rybg'))
  174. }).catch(() => {
  175. }).finally(() => {
  176. this.$modal.closeLoading()
  177. })
  178. },
  179. doSign(val){
  180. if(this.signType==='save'){
  181. this.doSave(val)
  182. }
  183. if(this.signType==='member'){
  184. this.doChangeMember(val)
  185. }
  186. },
  187. doSave(sign){
  188. this.$modal.loading()
  189. studySubject_save({
  190. studyId:this.study.id,
  191. subjectList:this.infoDialog.saveList,
  192. sign:sign
  193. }).then(() => {
  194. this.infoDialog.visible = false
  195. this.$refs.subjectSignRef.cancel()
  196. this.getList()
  197. }).finally(() => {
  198. this.$modal.closeLoading()
  199. })
  200. },
  201. chooseLeader(row){
  202. this.infoDialog.subject = row
  203. this.$refs.selectSubjectDeptUserDialog.show(this.infoDialog.subject.leader,this.infoDialog.subject.leaderName,this.infoDialog.subject.leaderNameEn)
  204. },
  205. changeSubject(val){
  206. this.infoDialog.subject.leader = val.id
  207. this.infoDialog.subject.leaderName = val.name
  208. this.infoDialog.subject.leaderNameEn = val.nameEn
  209. this.infoDialog.subject.select = true
  210. let index = _.findIndex(this.infoDialog.list,(item)=>{
  211. return item.deptId===this.infoDialog.subject.deptId
  212. })
  213. if(index>-1){
  214. this.infoDialog.list.splice(index,1,this.infoDialog.subject)
  215. }
  216. },
  217. yq(item){
  218. this.memberSubject = item
  219. studySubjectUser_getListByStudySubjectId({studySubjectId:item.id}).then(response => {
  220. let memberList = []
  221. for(let i=0;i<response.data.length;i++){
  222. memberList.push({
  223. id:response.data[i].userId,
  224. name:response.data[i].userName,
  225. nameEn:response.data[i].userNameEn,
  226. })
  227. }
  228. this.$refs.selectSubjectDeptUserMultipleDialog.show(memberList)
  229. }).finally(()=>{
  230. });
  231. },
  232. changeMember(val){
  233. let postList = []
  234. if(val.length>0){
  235. for(let i=0;i<val.length;i++){
  236. let item = val[i]
  237. postList.push({
  238. userId:item.id,
  239. userName:item.name,
  240. userNameEn:item.nameEn,
  241. })
  242. }
  243. }
  244. this.memberList = postList
  245. studySubjectUser_save({
  246. studySubjectId:this.memberSubject.id,
  247. subjectUserList:this.memberList,
  248. sign:{}
  249. }).then(() => {
  250. this.$refs.selectSubjectDeptUserMultipleDialog.close()
  251. this.signType = 'member'
  252. this.$refs.subjectSignRef.show(this.$t('page.business.study.study.rybg'),this.$t('page.business.study.study.rybg'))
  253. }).catch((e) => {
  254. }).finally(() => {
  255. })
  256. },
  257. doChangeMember(sign){
  258. this.$modal.loading()
  259. studySubjectUser_save({
  260. studySubjectId:this.memberSubject.id,
  261. subjectUserList:this.memberList,
  262. sign:sign
  263. }).then(() => {
  264. this.$refs.subjectSignRef.cancel()
  265. }).finally(() => {
  266. this.$modal.closeLoading()
  267. })
  268. },
  269. }
  270. }
  271. </script>
  272. <style lang="scss" scoped>
  273. .study-subject {
  274. .subject-top {
  275. background: #f0f7ff;
  276. border-top-left-radius: 3px;
  277. border-top-right-radius: 3px;
  278. border-top: 3px solid #409eff;
  279. padding: 20px 0;
  280. text-align: center;
  281. color: #409eff;
  282. font-weight: bold;
  283. }
  284. .subject-study{
  285. background: #fafcff;
  286. padding: 20px;
  287. color: #666666;
  288. position: relative;
  289. .study-info{
  290. margin-bottom: 20px;
  291. span{
  292. color: #777;
  293. }
  294. &:last-child{
  295. margin-bottom: 0;
  296. }
  297. }
  298. }
  299. .subject-operate{
  300. margin: 20px 0;
  301. display: flex;
  302. flex-direction: row;
  303. align-items: center;
  304. .operate-img{
  305. flex-shrink: 0;
  306. height: 15px;
  307. background: #3178ff;
  308. width: 3px;
  309. }
  310. .operate-left{
  311. flex-shrink: 0;
  312. font-weight: bold;
  313. padding-left: 10px;
  314. }
  315. .operate-right{
  316. flex-grow: 1;
  317. text-align: right;
  318. .operate-icon{
  319. cursor: pointer;
  320. }
  321. }
  322. }
  323. .subject-content{
  324. .subject-item{
  325. margin-bottom: 10px;
  326. padding: 10px;
  327. display: flex;
  328. flex-direction: row;
  329. align-items: center;
  330. justify-content: space-between;
  331. background: #f9fafc;
  332. border-radius: 5px;
  333. cursor: pointer;
  334. &.active{
  335. border: 1px solid #47a1ff;
  336. }
  337. .subject-item-name{
  338. color: #777;
  339. }
  340. .subject-item-add{
  341. }
  342. }
  343. }
  344. }
  345. .subject-table-box{
  346. display: flex;
  347. flex-direction: row;
  348. align-items: center;
  349. .subject-table-left{
  350. flex-shrink: 0;
  351. width: 60%;
  352. }
  353. .subject-table-right{
  354. flex-grow: 1;
  355. margin-left: 5px;
  356. }
  357. }
  358. </style>