questionnaireEdit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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" style="padding: 32rpx 24rpx 0;">
  22. <view class="box-title">问卷作答时间设置</view>
  23. <view class="box-time adfacjb" style="margin-top: 32rpx;" @click="startShow=true">
  24. <view class="box-time-left">开始时间</view>
  25. <view class="box-time-right adfac">
  26. <text>{{dto.startTime}}</text>
  27. <image :src="imgBase+'my_arrow_right.png'"></image>
  28. </view>
  29. </view>
  30. <view class="box-time adfacjb" @click="endShow=true">
  31. <view class="box-time-left">截止时间</view>
  32. <view class="box-time-right adfac">
  33. <text>{{dto.endTime}}</text>
  34. <image :src="imgBase+'my_arrow_right.png'"></image>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- <view class="box" style="padding: 32rpx 24rpx 18rpx;">
  39. <view class="box-title adfacjb">
  40. <text>限制每位用户提交次数</text>
  41. <u-switch v-model="limit" activeColor="#199C9C" size="38"></u-switch>
  42. </view>
  43. <view class="box-num adfacjb" v-if="limit">
  44. <view class="box-num-title">可提交次数</view>
  45. <view class="box-num-right">
  46. <cus-number-box ref="cnbRef" :min="1" :number="dto.answerSetting" @valChange="valChange"></cus-number-box>
  47. </view>
  48. </view>
  49. </view> -->
  50. <view class="box" style="padding: 30rpx 24rpx 0;" v-if="type==2&&!isEdit">
  51. <view class="box-title adfacjb" style="margin-bottom: 21rpx;">
  52. <text>团队人员</text>
  53. <view class="box-add" @click="addTeamUser">+ 添加</view>
  54. </view>
  55. <view class="box-user">
  56. <view class="box-user-item adfacjb" v-for="(item,index) in dto.memberList" :key="index">
  57. <view class="box-user-item-left">
  58. <view class="box-user-item-left-name adfac">
  59. <text>{{item.realName}}</text>
  60. <view class="type">{{item.categoryName}}</view>
  61. </view>
  62. <view class="box-user-item-left-email">{{item.email}}</view>
  63. </view>
  64. <image class="box-user-item-right" :src="imgBase+'icon_delete.png'" @click="deleteTeamUser(item,index)"></image>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="bottom">
  69. <view class="zt_btn" @click="confirmPublish">{{confirmText}}</view>
  70. </view>
  71. <cus-select :show="teamShow" :list="teamList" :addShow="true"
  72. @close="teamShow=false" @addTeam="addTeam" @confirmTeam="confirmTeam"></cus-select>
  73. <u-datetime-picker ref="datetimePicker1" title="开始时间" :minDate="minStartTime" itemHeight="88" :show="startShow" mode="datetime" :formatter="formatter" @cancel="startShow=false" @confirm="startConfirm"></u-datetime-picker>
  74. <u-datetime-picker ref="datetimePicker2" title="结束时间" :minDate="minEndTime" itemHeight="88" :show="endShow" mode="datetime" :formatter="formatter" @cancel="endShow=false" @confirm="endConfirm"></u-datetime-picker>
  75. </view>
  76. </template>
  77. <script>
  78. import CusNumberBox from '@/components/CusNumberBox/index.vue'
  79. import CusSelect from '@/components/CusSelect/index.vue'
  80. export default {
  81. components:{ CusNumberBox, CusSelect },
  82. data(){
  83. return {
  84. id:'',
  85. type:'',
  86. title:'编辑问卷',
  87. confirmText:'保存',
  88. questionnaireId:'',
  89. questionnaireName:'',
  90. limit:true,
  91. teamShow:false,
  92. startShow:false,
  93. endShow:false,
  94. dto:{
  95. memberList:[]
  96. },
  97. teamName:'请选择团队',
  98. teamList:[],
  99. minStartTime:new Date().getTime(),
  100. minEndTime:new Date().getTime(),
  101. isEdit:'',
  102. }
  103. },
  104. onReady() {
  105. this.$refs.datetimePicker1.setFormatter(this.formatter)
  106. this.$refs.datetimePicker2.setFormatter(this.formatter)
  107. },
  108. onLoad(options) {
  109. this.teamQuestionnaireId = options.teamQuestionnaireId;
  110. this.questionnaireId = options.questionnaireId;
  111. this.questionnaireName = options.questionnaireName;
  112. this.type = options.type;
  113. this.isEdit = options.isEdit;
  114. if(this.type==2){
  115. this.title = '发布问卷';
  116. this.confirmText = '确认发布';
  117. this.dto.answerSetting = 1;
  118. if(this.isEdit){
  119. this.title = '编辑问卷';
  120. this.getDetail()
  121. }
  122. }else if(this.type==1) this.getDetail()
  123. },
  124. methods:{
  125. formatter(type, value) {
  126. if (type === 'year') {
  127. return `${value}年`
  128. }
  129. if (type === 'month') {
  130. return `${value}月`
  131. }
  132. if (type === 'day') {
  133. return `${value}日`
  134. }
  135. if (type === 'hour') {
  136. return `${value}时`
  137. }
  138. if (type === 'minute') {
  139. return `${value}分`
  140. }
  141. return value
  142. },
  143. valChange(e){
  144. this.dto.answerSetting = e;
  145. },
  146. async getDetail(){
  147. this.$api.get('/core/team/questionnaire/'+this.teamQuestionnaireId).then(({data:res})=>{
  148. if(res.code!==0) return this.$showToast(res.msg)
  149. this.dto = {...this.dto,...res.data}
  150. this.questionnaireId = this.dto.questionnaireId;
  151. this.$refs.cnbRef.value = this.dto.answerSetting;
  152. this.teamName = res.data.teamName;
  153. })
  154. },
  155. showTeam(){
  156. this.teamShow = true;
  157. this.$api.get('/core/user/team/page',{
  158. page:1,
  159. limit:-1,
  160. coachId:JSON.parse(uni.getStorageSync('userInfo')).id
  161. }).then(({data:res})=>{
  162. if(res.code!==0) return this.$showToast(res.msg)
  163. this.teamList = res.data.list;
  164. this.teamList.forEach(t=>t.name=t.teamName)
  165. })
  166. },
  167. handlePreview(){
  168. uni.navigateTo({
  169. url:`/pagesPublish/questionnairePreview?questionnaireName=${this.questionnaireName}&teamQuestionnaireId=${this.teamQuestionnaireId}&type=${this.type}`
  170. })
  171. },
  172. addTeam(){
  173. uni.navigateTo({
  174. url:'/pagesPublish/fillTeamInfo?type=add&questionnaireId='+this.questionnaireId,
  175. events:{
  176. saveTeamInfo: data =>{
  177. this.$api.get('/core/user/team/page',{
  178. page:1,
  179. limit:-1,
  180. coachId:JSON.parse(uni.getStorageSync('userInfo')).id
  181. }).then(({data:res})=>{
  182. if(res.code!==0) return this.$showToast(res.msg)
  183. this.teamList = res.data.list;
  184. this.teamList.forEach(t=>t.name=t.teamName)
  185. })
  186. }
  187. }
  188. })
  189. },
  190. addTeamUser(){
  191. uni.navigateTo({
  192. url:'/pagesMy/teamUser?type=select',
  193. success: (res) => {
  194. res.eventChannel.emit('acceptDataFromOpenerPage', { data: '来自A页面的初始数据' });
  195. },
  196. events:{
  197. selectUserConfirm: data => {
  198. this.dto.memberList = data;
  199. }
  200. }
  201. })
  202. },
  203. deleteTeamUser(item,index){
  204. this.dto.memberList.splice(index,1);
  205. },
  206. confirmTeam(item){
  207. this.teamName = item.teamName;
  208. this.dto.teamId = item.id;
  209. this.teamShow = false;
  210. },
  211. startConfirm(e){
  212. this.dto.startTime = new Date(e.value).Format('yyyy-MM-dd hh:mm:ss');
  213. this.minEndTime = e.value;
  214. this.startShow = false;
  215. },
  216. endConfirm(e){
  217. this.dto.endTime = new Date(e.value).Format('yyyy-MM-dd hh:mm:ss');
  218. this.endShow = false;
  219. },
  220. confirmPublish(){
  221. let params = JSON.parse(JSON.stringify(this.dto));
  222. params.coachId = JSON.parse(uni.getStorageSync('userInfo')).id;
  223. params.type = this.type;
  224. params.answerSetting = 1;
  225. if(!params?.teamId) return this.$showToast('请选择团队')
  226. if(!params?.startTime) return this.$showToast('请选择开始时间')
  227. if(!params?.endTime) return this.$showToast('请选择结束时间')
  228. if(params?.memberList.length==0&&!this.isEdit) return this.$showToast('请选择团队人员')
  229. let url = '/core/team/questionnaire';
  230. let method = 'put';
  231. if(this.type==2){
  232. url = '/core/team/questionnaire/publish';
  233. method = 'post'
  234. params.questionnaireId = this.questionnaireId
  235. if(this.isEdit){
  236. url = '/core/team/questionnaire';
  237. method = 'put';
  238. }
  239. }
  240. this.$api[method](url,params).then(({data:res})=>{
  241. if(res.code!==0) return this.$showToast(res.msg)
  242. this.$showToast('操作成功')
  243. setTimeout(()=>{
  244. if(this.type==2){
  245. if(this.isEdit) return uni.navigateBack()
  246. uni.navigateTo({ url:'/pagesPublish/publishResult?title='+this.questionnaireName+'&teamQuestionnaireId='+res.data })
  247. }else uni.navigateBack()
  248. },1500)
  249. })
  250. }
  251. }
  252. }
  253. </script>
  254. <style scoped lang="scss">
  255. .default_page{
  256. padding: 0 24rpx 182rpx;
  257. box-sizing: border-box;
  258. .box{
  259. background: #FFFFFF;
  260. box-shadow: inset 0rpx -1rpx 0rpx 0rpx rgba(229,231,235,0.5);
  261. border-radius: 24rpx;
  262. margin-top: 20rpx;
  263. overflow: hidden;
  264. &-title,&-title>text{
  265. font-family: PingFang-SC, PingFang-SC;
  266. font-weight: bold;
  267. font-size: 32rpx;
  268. color: #002846;
  269. line-height: 32rpx;
  270. }
  271. &-tip{
  272. font-family: PingFangSC, PingFang SC;
  273. font-weight: 400;
  274. font-size: 30rpx;
  275. color: #667E90;
  276. line-height: 32rpx;
  277. overflow: hidden;
  278. text-overflow: ellipsis;
  279. white-space: nowrap;
  280. }
  281. &-left{
  282. width: calc(100% - 150rpx);
  283. }
  284. &-right{
  285. &>text{
  286. font-family: PingFangSC, PingFang SC;
  287. font-weight: 400;
  288. font-size: 26rpx;
  289. color: #33A7A7;
  290. line-height: 32rpx;
  291. }
  292. &>image{
  293. width: 32rpx;
  294. height: 32rpx;
  295. margin-left: 10rpx;
  296. }
  297. }
  298. &-team{
  299. margin-top: 31rpx;
  300. &>image{
  301. width: 36rpx;
  302. height: 36rpx;
  303. }
  304. }
  305. &-time{
  306. padding: 33rpx 0;
  307. box-shadow: inset 0rpx -1rpx 0rpx 0rpx rgba(229,231,235,0.5);
  308. &-left{
  309. font-family: PingFangSC, PingFang SC;
  310. font-weight: 400;
  311. font-size: 30rpx;
  312. color: #002846;
  313. line-height: 32rpx;
  314. }
  315. &-right{
  316. &>text{
  317. font-family: PingFangSC, PingFang SC;
  318. font-weight: 400;
  319. font-size: 30rpx;
  320. color: #667E90;
  321. line-height: 32rpx;
  322. }
  323. &>image{
  324. width: 36rpx;
  325. height: 36rpx;
  326. margin-left: 10rpx;
  327. }
  328. }
  329. }
  330. &-num{
  331. margin-top: 65rpx;
  332. &-left{
  333. font-family: PingFangSC, PingFang SC;
  334. font-weight: 400;
  335. font-size: 30rpx;
  336. color: #002846;
  337. line-height: 32rpx;
  338. }
  339. }
  340. &-add{
  341. width: 120rpx;
  342. height: 54rpx;
  343. border-radius: 27rpx;
  344. border: 1rpx solid #33A7A7;
  345. font-family: PingFang-SC, PingFang-SC;
  346. font-weight: bold;
  347. font-size: 24rpx;
  348. color: #33A7A7;
  349. line-height: 54rpx;
  350. text-align: center;
  351. }
  352. &-user{
  353. &-item{
  354. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #EFEFEF;
  355. border-radius: 24rpx;
  356. padding: 30rpx 0 36rpx;
  357. &-left{
  358. &-name{
  359. text{
  360. font-family: PingFangSC, PingFang SC;
  361. font-weight: 400;
  362. font-size: 30rpx;
  363. color: #002846;
  364. line-height: 32rpx;
  365. }
  366. .type{
  367. background: #FFF7DC;
  368. border-radius: 21rpx;
  369. margin-left: 20rpx;
  370. padding: 5rpx 16rpx;
  371. font-family: PingFangSC, PingFang SC;
  372. font-weight: 400;
  373. font-size: 22rpx;
  374. color: #BA9B31;
  375. line-height: 30rpx;
  376. text-align: center;
  377. }
  378. }
  379. &-email{
  380. font-family: PingFangSC, PingFang SC;
  381. font-weight: 400;
  382. font-size: 28rpx;
  383. color: #667E90;
  384. line-height: 28rpx;
  385. margin-top: 20rpx;
  386. }
  387. }
  388. &-right{
  389. width: 36rpx;
  390. height: 36rpx;
  391. }
  392. }
  393. }
  394. }
  395. .bottom{
  396. width: 100%;
  397. height: 162rpx;
  398. background: #FFFFFF;
  399. padding: 20rpx 50rpx;
  400. box-sizing: border-box;
  401. position: fixed;
  402. left: 0;
  403. bottom: 0;
  404. z-index: 888;
  405. }
  406. }
  407. </style>