questionnaireEdit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. return value
  136. },
  137. valChange(e){
  138. this.dto.answerSetting = e;
  139. },
  140. async getDetail(){
  141. this.$api.get('/core/team/questionnaire/'+this.teamQuestionnaireId).then(({data:res})=>{
  142. if(res.code!==0) return this.$showToast(res.msg)
  143. this.dto = {...this.dto,...res.data}
  144. this.questionnaireId = this.dto.questionnaireId;
  145. this.$refs.cnbRef.value = this.dto.answerSetting;
  146. this.teamName = res.data.teamName;
  147. })
  148. },
  149. showTeam(){
  150. this.teamShow = true;
  151. this.$api.get('/core/user/team/page',{
  152. page:1,
  153. limit:-1,
  154. coachId:JSON.parse(uni.getStorageSync('userInfo')).id
  155. }).then(({data:res})=>{
  156. if(res.code!==0) return this.$showToast(res.msg)
  157. this.teamList = res.data.list;
  158. this.teamList.forEach(t=>t.name=t.teamName)
  159. })
  160. },
  161. handlePreview(){
  162. uni.navigateTo({
  163. url:`/pagesPublish/questionnairePreview?questionnaireName=${this.questionnaireName}&teamQuestionnaireId=${this.teamQuestionnaireId}&type=${this.type}`
  164. })
  165. },
  166. addTeam(){
  167. uni.navigateTo({
  168. url:'/pagesPublish/fillTeamInfo?type=add&questionnaireId='+this.questionnaireId,
  169. events:{
  170. saveTeamInfo: data =>{
  171. this.$api.get('/core/user/team/page',{
  172. page:1,
  173. limit:-1,
  174. coachId:JSON.parse(uni.getStorageSync('userInfo')).id
  175. }).then(({data:res})=>{
  176. if(res.code!==0) return this.$showToast(res.msg)
  177. this.teamList = res.data.list;
  178. this.teamList.forEach(t=>t.name=t.teamName)
  179. })
  180. }
  181. }
  182. })
  183. },
  184. addTeamUser(){
  185. uni.navigateTo({
  186. url:'/pagesMy/teamUser?type=select',
  187. success: (res) => {
  188. res.eventChannel.emit('acceptDataFromOpenerPage', { data: '来自A页面的初始数据' });
  189. },
  190. events:{
  191. selectUserConfirm: data => {
  192. this.dto.memberList = data;
  193. }
  194. }
  195. })
  196. },
  197. deleteTeamUser(item,index){
  198. this.dto.memberList.splice(index,1);
  199. },
  200. confirmTeam(item){
  201. this.teamName = item.teamName;
  202. this.dto.teamId = item.id;
  203. this.teamShow = false;
  204. },
  205. startConfirm(e){
  206. this.dto.startTime = new Date(e.value).Format('yyyy-MM-dd hh:mm:ss');
  207. this.minEndTime = e.value;
  208. this.startShow = false;
  209. },
  210. endConfirm(e){
  211. this.dto.endTime = new Date(e.value).Format('yyyy-MM-dd hh:mm:ss');
  212. this.endShow = false;
  213. },
  214. confirmPublish(){
  215. let params = JSON.parse(JSON.stringify(this.dto));
  216. params.coachId = JSON.parse(uni.getStorageSync('userInfo')).id;
  217. params.type = this.type;
  218. if(!params?.teamId) return this.$showToast('请选择团队')
  219. if(!params?.startTime) return this.$showToast('请选择开始时间')
  220. if(!params?.endTime) return this.$showToast('请选择结束时间')
  221. if(params?.memberList.length==0&&!this.isEdit) return this.$showToast('请选择团队人员')
  222. let url = '/core/team/questionnaire';
  223. let method = 'put';
  224. if(this.type==2){
  225. url = '/core/team/questionnaire/publish';
  226. method = 'post'
  227. params.questionnaireId = this.questionnaireId
  228. if(this.isEdit){
  229. url = '/core/team/questionnaire';
  230. method = 'put';
  231. }
  232. }
  233. this.$api[method](url,params).then(({data:res})=>{
  234. if(res.code!==0) return this.$showToast(res.msg)
  235. this.$showToast('操作成功')
  236. setTimeout(()=>{
  237. if(this.type==2){
  238. if(this.isEdit) return uni.navigateBack()
  239. uni.navigateTo({ url:'/pagesPublish/publishResult?title='+this.questionnaireName+'&teamQuestionnaireId='+res.data })
  240. }else uni.navigateBack()
  241. },1500)
  242. })
  243. }
  244. }
  245. }
  246. </script>
  247. <style scoped lang="scss">
  248. .default_page{
  249. padding: 0 24rpx 182rpx;
  250. box-sizing: border-box;
  251. .box{
  252. background: #FFFFFF;
  253. box-shadow: inset 0rpx -1rpx 0rpx 0rpx rgba(229,231,235,0.5);
  254. border-radius: 24rpx;
  255. margin-top: 20rpx;
  256. overflow: hidden;
  257. &-title,&-title>text{
  258. font-family: PingFang-SC, PingFang-SC;
  259. font-weight: bold;
  260. font-size: 32rpx;
  261. color: #002846;
  262. line-height: 32rpx;
  263. }
  264. &-tip{
  265. font-family: PingFangSC, PingFang SC;
  266. font-weight: 400;
  267. font-size: 30rpx;
  268. color: #667E90;
  269. line-height: 32rpx;
  270. overflow: hidden;
  271. text-overflow: ellipsis;
  272. white-space: nowrap;
  273. }
  274. &-left{
  275. width: calc(100% - 150rpx);
  276. }
  277. &-right{
  278. &>text{
  279. font-family: PingFangSC, PingFang SC;
  280. font-weight: 400;
  281. font-size: 26rpx;
  282. color: #33A7A7;
  283. line-height: 32rpx;
  284. }
  285. &>image{
  286. width: 32rpx;
  287. height: 32rpx;
  288. margin-left: 10rpx;
  289. }
  290. }
  291. &-team{
  292. margin-top: 31rpx;
  293. &>image{
  294. width: 36rpx;
  295. height: 36rpx;
  296. }
  297. }
  298. &-time{
  299. padding: 33rpx 0;
  300. box-shadow: inset 0rpx -1rpx 0rpx 0rpx rgba(229,231,235,0.5);
  301. &-left{
  302. font-family: PingFangSC, PingFang SC;
  303. font-weight: 400;
  304. font-size: 30rpx;
  305. color: #002846;
  306. line-height: 32rpx;
  307. }
  308. &-right{
  309. &>text{
  310. font-family: PingFangSC, PingFang SC;
  311. font-weight: 400;
  312. font-size: 30rpx;
  313. color: #667E90;
  314. line-height: 32rpx;
  315. }
  316. &>image{
  317. width: 36rpx;
  318. height: 36rpx;
  319. margin-left: 10rpx;
  320. }
  321. }
  322. }
  323. &-num{
  324. margin-top: 65rpx;
  325. &-left{
  326. font-family: PingFangSC, PingFang SC;
  327. font-weight: 400;
  328. font-size: 30rpx;
  329. color: #002846;
  330. line-height: 32rpx;
  331. }
  332. }
  333. &-add{
  334. width: 120rpx;
  335. height: 54rpx;
  336. border-radius: 27rpx;
  337. border: 1rpx solid #33A7A7;
  338. font-family: PingFang-SC, PingFang-SC;
  339. font-weight: bold;
  340. font-size: 24rpx;
  341. color: #33A7A7;
  342. line-height: 54rpx;
  343. text-align: center;
  344. }
  345. &-user{
  346. &-item{
  347. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #EFEFEF;
  348. border-radius: 24rpx;
  349. padding: 30rpx 0 36rpx;
  350. &-left{
  351. &-name{
  352. text{
  353. font-family: PingFangSC, PingFang SC;
  354. font-weight: 400;
  355. font-size: 30rpx;
  356. color: #002846;
  357. line-height: 32rpx;
  358. }
  359. .type{
  360. background: #FFF7DC;
  361. border-radius: 21rpx;
  362. margin-left: 20rpx;
  363. padding: 5rpx 16rpx;
  364. font-family: PingFangSC, PingFang SC;
  365. font-weight: 400;
  366. font-size: 22rpx;
  367. color: #BA9B31;
  368. line-height: 30rpx;
  369. text-align: center;
  370. }
  371. }
  372. &-email{
  373. font-family: PingFangSC, PingFang SC;
  374. font-weight: 400;
  375. font-size: 28rpx;
  376. color: #667E90;
  377. line-height: 28rpx;
  378. margin-top: 20rpx;
  379. }
  380. }
  381. &-right{
  382. width: 36rpx;
  383. height: 36rpx;
  384. }
  385. }
  386. }
  387. }
  388. .bottom{
  389. width: 100%;
  390. height: 162rpx;
  391. background: #FFFFFF;
  392. padding: 20rpx 50rpx;
  393. box-sizing: border-box;
  394. position: fixed;
  395. left: 0;
  396. bottom: 0;
  397. z-index: 888;
  398. }
  399. }
  400. </style>