questionnaireEdit.vue 12 KB

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