questionnaireEdit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <view class="default_page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header :title='title'></cus-header>
  4. <view class="box adfacjb" style="padding: 32rpx 24rpx 40rpx;">
  5. <view class="box-left">
  6. <view class="box-title">问卷名称</view>
  7. <view class="box-tip" style="margin-top: 32rpx;">{{questionnaireName}}</view>
  8. </view>
  9. <view class="box-right adfac" @click="handlePreview">
  10. <text>预览</text>
  11. <image :src="imgBase+'my_arrow_right.png'"></image>
  12. </view>
  13. </view>
  14. <view class="box" style="padding: 32rpx 24rpx;" @click="showTeam">
  15. <view class="box-title">选择团队</view>
  16. <view class="box-team adfacjb" @click="showTeam">
  17. <view class="box-tip">{{teamName}}</view>
  18. <image :src="imgBase+'my_arrow_right.png'"></image>
  19. </view>
  20. </view>
  21. <view class="box background-survey-row adfacjb" v-if="type==2" @click="openBackgroundSurvey">
  22. <view>
  23. <view class="box-title">团队背景调研</view>
  24. <view class="background-survey-tip">随本次PERILL评估附带,发布前必须完成</view>
  25. </view>
  26. <view class="background-survey-status adfac" :class="{completed:backgroundSurveyStatus==='COMPLETED'}">
  27. <text>{{backgroundSurveyStatus==='COMPLETED'?'已完成':'待完成'}}</text>
  28. <image :src="imgBase+'my_arrow_right.png'"></image>
  29. </view>
  30. </view>
  31. <view class="box" style="padding: 32rpx 24rpx 0;">
  32. <view class="box-title">问卷作答时间设置</view>
  33. <view class="box-time adfacjb" style="margin-top: 32rpx;" @click="startShow=true">
  34. <view class="box-time-left">开始时间</view>
  35. <view class="box-time-right adfac">
  36. <text>{{dto.startTime}}</text>
  37. <image :src="imgBase+'my_arrow_right.png'"></image>
  38. </view>
  39. </view>
  40. <view class="box-time adfacjb" @click="endShow=true">
  41. <view class="box-time-left">截止时间</view>
  42. <view class="box-time-right adfac">
  43. <text>{{dto.endTime}}</text>
  44. <image :src="imgBase+'my_arrow_right.png'"></image>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- <view class="box" style="padding: 32rpx 24rpx 18rpx;">
  49. <view class="box-title adfacjb">
  50. <text>限制每位用户提交次数</text>
  51. <u-switch v-model="limit" activeColor="#199C9C" size="38"></u-switch>
  52. </view>
  53. <view class="box-num adfacjb" v-if="limit">
  54. <view class="box-num-title">可提交次数</view>
  55. <view class="box-num-right">
  56. <cus-number-box ref="cnbRef" :min="1" :number="dto.answerSetting" @valChange="valChange"></cus-number-box>
  57. </view>
  58. </view>
  59. </view> -->
  60. <view class="box" style="padding: 30rpx 24rpx 0;" v-if="type==2&&!isEdit">
  61. <view class="box-title adfacjb" style="margin-bottom: 21rpx;">
  62. <text>团队人员</text>
  63. <view class="box-add" @click="addTeamUser">+ 添加</view>
  64. </view>
  65. <view class="box-user">
  66. <view class="box-user-item adfacjb" v-for="(item,index) in dto.memberList" :key="index">
  67. <view class="box-user-item-left">
  68. <view class="box-user-item-left-name adfac">
  69. <text>{{item.realName}}</text>
  70. <view class="type">{{item.categoryName}}</view>
  71. </view>
  72. <view class="box-user-item-left-email">{{item.email}}</view>
  73. </view>
  74. <image class="box-user-item-right" :src="imgBase+'icon_delete.png'" @click="deleteTeamUser(item,index)"></image>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="bottom">
  79. <view class="zt_btn" @click="confirmPublish">{{confirmText}}</view>
  80. </view>
  81. <cus-select :show="teamShow" :list="teamList" :addShow="true" :team="true"
  82. @close="teamShow=false" @addTeam="addTeam" @confirmTeam="confirmTeam"></cus-select>
  83. <u-datetime-picker ref="datetimePicker1" title="开始时间" :minDate="minStartTime" itemHeight="88" :show="startShow" mode="datetime" :formatter="formatter" @cancel="startShow=false" @confirm="startConfirm"></u-datetime-picker>
  84. <u-datetime-picker ref="datetimePicker2" title="结束时间" :minDate="minEndTime" itemHeight="88" :show="endShow" mode="datetime" :formatter="formatter" @cancel="endShow=false" @confirm="endConfirm"></u-datetime-picker>
  85. </view>
  86. </template>
  87. <script>
  88. import CusNumberBox from '@/components/CusNumberBox/index.vue'
  89. import CusSelect from '@/components/CusSelect/index.vue'
  90. export default {
  91. components:{ CusNumberBox, CusSelect },
  92. data(){
  93. return {
  94. id:'',
  95. type:'',
  96. title:'编辑问卷',
  97. confirmText:'保存',
  98. questionnaireId:'',
  99. questionnaireName:'',
  100. limit:true,
  101. teamShow:false,
  102. startShow:false,
  103. endShow:false,
  104. dto:{
  105. memberList:[]
  106. },
  107. teamName:'请选择团队',
  108. teamList:[],
  109. minStartTime:new Date().getTime(),
  110. minEndTime:new Date().getTime(),
  111. isEdit:'',
  112. backgroundSurveyId:'',
  113. backgroundSurveyStatus:'DRAFT',
  114. }
  115. },
  116. onReady() {
  117. this.$refs.datetimePicker1.setFormatter(this.formatter)
  118. this.$refs.datetimePicker2.setFormatter(this.formatter)
  119. },
  120. onLoad(options) {
  121. this.teamQuestionnaireId = options.teamQuestionnaireId;
  122. this.questionnaireId = options.questionnaireId;
  123. this.questionnaireName = options.questionnaireName;
  124. this.type = options.type;
  125. this.isEdit = options.isEdit;
  126. if(this.type==2){
  127. this.title = '发布问卷';
  128. this.confirmText = '确认发布';
  129. this.dto.answerSetting = 1;
  130. if(this.isEdit){
  131. this.title = '编辑问卷';
  132. this.getDetail()
  133. }
  134. }else if(this.type==1) this.getDetail()
  135. },
  136. methods:{
  137. formatter(type, value) {
  138. if (type === 'year') {
  139. return `${value}年`
  140. }
  141. if (type === 'month') {
  142. return `${value}月`
  143. }
  144. if (type === 'day') {
  145. return `${value}日`
  146. }
  147. if (type === 'hour') {
  148. return `${value}时`
  149. }
  150. if (type === 'minute') {
  151. return `${value}分`
  152. }
  153. return value
  154. },
  155. valChange(e){
  156. this.dto.answerSetting = e;
  157. },
  158. async getDetail(){
  159. this.$api.get('/core/team/questionnaire/'+this.teamQuestionnaireId).then(({data:res})=>{
  160. if(res.code!==0) return this.$showToast(res.msg)
  161. this.dto = {...this.dto,...res.data}
  162. this.questionnaireId = this.dto.questionnaireId;
  163. if(this.$refs.cnbRef) this.$refs.cnbRef.value = this.dto.answerSetting;
  164. this.teamName = res.data.teamName;
  165. this.loadCoachBackgroundSurvey()
  166. })
  167. },
  168. async loadCoachBackgroundSurvey(){
  169. if(!this.teamQuestionnaireId) return
  170. try {
  171. const { data:res } = await this.$api.get(
  172. `/core/background/survey/coach/team-questionnaire/${this.teamQuestionnaireId}`)
  173. if(res.code!==0) throw new Error(res.msg)
  174. this.backgroundSurveyId = res.data.id
  175. this.backgroundSurveyStatus = res.data.status
  176. } catch(error) {
  177. this.backgroundSurveyStatus = 'DRAFT'
  178. }
  179. },
  180. openBackgroundSurvey(){
  181. if(!this.dto.teamId) return this.$showToast('请先选择团队')
  182. const query = this.isEdit
  183. ? `mode=coach&teamQuestionnaireId=${encodeURIComponent(this.teamQuestionnaireId)}`
  184. : `mode=coach&teamId=${encodeURIComponent(this.dto.teamId)}&surveyId=${encodeURIComponent(this.backgroundSurveyId || '')}`
  185. uni.navigateTo({
  186. url:`/pagesPublish/backgroundSurvey?${query}`,
  187. events:{
  188. backgroundSurveyReady:data=>{
  189. this.backgroundSurveyId = data.surveyId
  190. this.backgroundSurveyStatus = data.status
  191. },
  192. backgroundSurveyCompleted:data=>{
  193. this.backgroundSurveyId = data.surveyId
  194. this.backgroundSurveyStatus = data.status
  195. }
  196. }
  197. })
  198. },
  199. showTeam(){
  200. this.teamShow = true;
  201. this.$api.get('/core/user/team/page',{
  202. page:1,
  203. limit:-1,
  204. coachId:JSON.parse(uni.getStorageSync('userInfo')).id
  205. }).then(({data:res})=>{
  206. if(res.code!==0) return this.$showToast(res.msg)
  207. // this.teamList = res.data.list.filter(l=>l.hierarchy&&l.scale);
  208. this.teamList = res.data.list;
  209. this.teamList.forEach(t=>t.name=t.teamName)
  210. })
  211. },
  212. handlePreview(){
  213. uni.navigateTo({
  214. url:`/pagesPublish/questionnairePreview?questionnaireName=${this.questionnaireName}&teamQuestionnaireId=${this.teamQuestionnaireId || ''}&questionnaireId=${this.questionnaireId || ''}&backgroundSurveyId=${this.backgroundSurveyId || ''}&type=${this.type}`
  215. })
  216. },
  217. addTeam(){
  218. uni.navigateTo({
  219. url:'/pagesPublish/fillTeamInfo?type=add&qtype=team&questionnaireId='+this.questionnaireId,
  220. events:{
  221. saveTeamInfo: data =>{
  222. if(data && data.teamId){
  223. this.dto.teamId = data.teamId
  224. this.teamName = data.teamName || '新建团队'
  225. this.backgroundSurveyId = ''
  226. this.backgroundSurveyStatus = 'DRAFT'
  227. }
  228. this.$api.get('/core/user/team/page',{
  229. page:1,
  230. limit:-1,
  231. coachId:JSON.parse(uni.getStorageSync('userInfo')).id
  232. }).then(({data:res})=>{
  233. if(res.code!==0) return this.$showToast(res.msg)
  234. // this.teamList = res.data.list.filter(l=>l.hierarchy&&l.scale);
  235. this.teamList = res.data.list;
  236. this.teamList.forEach(t=>t.name=t.teamName)
  237. })
  238. }
  239. }
  240. })
  241. },
  242. addTeamUser(){
  243. uni.navigateTo({
  244. url:'/pagesMy/teamUser?type=select',
  245. success: (res) => {
  246. res.eventChannel.emit('acceptDataFromOpenerPage', { data: '来自A页面的初始数据' });
  247. },
  248. events:{
  249. selectUserConfirm: data => {
  250. this.dto.memberList = data;
  251. }
  252. }
  253. })
  254. },
  255. deleteTeamUser(item,index){
  256. this.dto.memberList.splice(index,1);
  257. },
  258. confirmTeam(item){
  259. if(!item) return this.$showToast('请选择团队')
  260. if(this.dto.teamId != item.id){
  261. this.backgroundSurveyId = ''
  262. this.backgroundSurveyStatus = 'DRAFT'
  263. }
  264. this.teamName = item.teamName;
  265. this.dto.teamId = item.id;
  266. this.teamShow = false;
  267. },
  268. startConfirm(e){
  269. this.dto.startTime = new Date(e.value).Format('yyyy-MM-dd hh:mm:ss');
  270. this.minEndTime = e.value;
  271. this.startShow = false;
  272. },
  273. endConfirm(e){
  274. this.dto.endTime = new Date(e.value).Format('yyyy-MM-dd hh:mm:ss');
  275. this.endShow = false;
  276. },
  277. confirmPublish(){
  278. let params = JSON.parse(JSON.stringify(this.dto));
  279. params.coachId = JSON.parse(uni.getStorageSync('userInfo')).id;
  280. params.type = this.type;
  281. params.answerSetting = 1;
  282. if(!params?.teamId) return this.$showToast('请选择团队')
  283. if(this.type==2 && this.backgroundSurveyStatus!=='COMPLETED'){
  284. return uni.showModal({
  285. title:'团队背景调研未完成',
  286. content:'为了帮助教练更好地对团队现状做评估,请先完成团队背景调研',
  287. showCancel:false,
  288. confirmColor:'#199C9C'
  289. })
  290. }
  291. if(!params?.startTime) return this.$showToast('请选择开始时间')
  292. if(!params?.endTime) return this.$showToast('请选择结束时间')
  293. if(params?.memberList.length==0&&!this.isEdit) return this.$showToast('请选择团队人员')
  294. let url = '/core/team/questionnaire';
  295. let method = 'put';
  296. if(this.type==2){
  297. url = '/core/team/questionnaire/publish';
  298. method = 'post'
  299. params.questionnaireId = this.questionnaireId
  300. params.backgroundSurveyId = this.backgroundSurveyId
  301. if(this.isEdit){
  302. url = '/core/team/questionnaire';
  303. method = 'put';
  304. }
  305. }
  306. this.$api[method](url,params).then(({data:res})=>{
  307. if(res.code!==0) return this.$showToast(res.msg)
  308. this.$showToast('操作成功')
  309. setTimeout(()=>{
  310. if(this.type==2){
  311. if(this.isEdit) return uni.navigateBack()
  312. uni.navigateTo({ url:'/pagesPublish/publishResult?title='+this.questionnaireName+'&teamQuestionnaireId='+res.data })
  313. }else uni.navigateBack()
  314. },1500)
  315. })
  316. }
  317. }
  318. }
  319. </script>
  320. <style scoped lang="scss">
  321. .default_page{
  322. padding: 0 24rpx 182rpx;
  323. box-sizing: border-box;
  324. .box{
  325. background: #FFFFFF;
  326. box-shadow: inset 0rpx -1rpx 0rpx 0rpx rgba(229,231,235,0.5);
  327. border-radius: 24rpx;
  328. margin-top: 20rpx;
  329. overflow: hidden;
  330. &-title,&-title>text{
  331. font-family: PingFang-SC, PingFang-SC;
  332. font-weight: bold;
  333. font-size: 32rpx;
  334. color: #002846;
  335. line-height: 32rpx;
  336. }
  337. &-tip{
  338. font-family: PingFangSC, PingFang SC;
  339. font-weight: 400;
  340. font-size: 30rpx;
  341. color: #667E90;
  342. line-height: 32rpx;
  343. overflow: hidden;
  344. text-overflow: ellipsis;
  345. white-space: nowrap;
  346. }
  347. &-left{
  348. width: calc(100% - 150rpx);
  349. }
  350. &-right{
  351. &>text{
  352. font-family: PingFangSC, PingFang SC;
  353. font-weight: 400;
  354. font-size: 26rpx;
  355. color: #33A7A7;
  356. line-height: 32rpx;
  357. }
  358. &>image{
  359. width: 32rpx;
  360. height: 32rpx;
  361. margin-left: 10rpx;
  362. }
  363. }
  364. &-team{
  365. margin-top: 31rpx;
  366. &>image{
  367. width: 36rpx;
  368. height: 36rpx;
  369. }
  370. }
  371. &-time{
  372. padding: 33rpx 0;
  373. box-shadow: inset 0rpx -1rpx 0rpx 0rpx rgba(229,231,235,0.5);
  374. &-left{
  375. font-family: PingFangSC, PingFang SC;
  376. font-weight: 400;
  377. font-size: 30rpx;
  378. color: #002846;
  379. line-height: 32rpx;
  380. }
  381. &-right{
  382. &>text{
  383. font-family: PingFangSC, PingFang SC;
  384. font-weight: 400;
  385. font-size: 30rpx;
  386. color: #667E90;
  387. line-height: 32rpx;
  388. }
  389. &>image{
  390. width: 36rpx;
  391. height: 36rpx;
  392. margin-left: 10rpx;
  393. }
  394. }
  395. }
  396. &-num{
  397. margin-top: 65rpx;
  398. &-left{
  399. font-family: PingFangSC, PingFang SC;
  400. font-weight: 400;
  401. font-size: 30rpx;
  402. color: #002846;
  403. line-height: 32rpx;
  404. }
  405. }
  406. &-add{
  407. width: 120rpx;
  408. height: 54rpx;
  409. border-radius: 27rpx;
  410. border: 1rpx solid #33A7A7;
  411. font-family: PingFang-SC, PingFang-SC;
  412. font-weight: bold;
  413. font-size: 24rpx;
  414. color: #33A7A7;
  415. line-height: 54rpx;
  416. text-align: center;
  417. }
  418. &-user{
  419. &-item{
  420. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #EFEFEF;
  421. border-radius: 24rpx;
  422. padding: 30rpx 0 36rpx;
  423. &-left{
  424. &-name{
  425. text{
  426. font-family: PingFangSC, PingFang SC;
  427. font-weight: 400;
  428. font-size: 30rpx;
  429. color: #002846;
  430. line-height: 32rpx;
  431. }
  432. .type{
  433. background: #FFF7DC;
  434. border-radius: 21rpx;
  435. margin-left: 20rpx;
  436. padding: 5rpx 16rpx;
  437. font-family: PingFangSC, PingFang SC;
  438. font-weight: 400;
  439. font-size: 22rpx;
  440. color: #BA9B31;
  441. line-height: 30rpx;
  442. text-align: center;
  443. }
  444. }
  445. &-email{
  446. font-family: PingFangSC, PingFang SC;
  447. font-weight: 400;
  448. font-size: 28rpx;
  449. color: #667E90;
  450. line-height: 28rpx;
  451. margin-top: 20rpx;
  452. }
  453. }
  454. &-right{
  455. width: 36rpx;
  456. height: 36rpx;
  457. }
  458. }
  459. }
  460. }
  461. .bottom{
  462. width: 100%;
  463. height: 162rpx;
  464. background: #FFFFFF;
  465. padding: 20rpx 50rpx;
  466. box-sizing: border-box;
  467. position: fixed;
  468. left: 0;
  469. bottom: 0;
  470. z-index: 888;
  471. }
  472. .background-survey-row{
  473. padding:32rpx 24rpx;
  474. }
  475. .background-survey-tip{
  476. font-size:24rpx;
  477. color:#8A9BA8;
  478. line-height:34rpx;
  479. margin-top:18rpx;
  480. }
  481. .background-survey-status{
  482. font-size:28rpx;
  483. color:#FD4F66;
  484. flex:none;
  485. &.completed{
  486. color:#199C9C;
  487. }
  488. image{
  489. width:36rpx;
  490. height:36rpx;
  491. margin-left:10rpx;
  492. }
  493. }
  494. }
  495. </style>