questionnaireEdit.vue 12 KB

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