satisfactionQuestions.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. <template>
  2. <view class="container">
  3. <scroll-view
  4. class="scroll_view"
  5. scroll-y
  6. scroll-with-animation
  7. scroll-anchoring
  8. :scroll-into-view="point"
  9. >
  10. <view class="top_bg_box">
  11. <image mode="widthFix" :src="icon.satisfaction.ques_top_bg"></image>
  12. <view class="ques_introduce displayFlexCol">
  13. <text>{{ quesList.SubjectTitle }}</text>
  14. <text>{{ quesList.Remark }}</text>
  15. </view>
  16. </view>
  17. <view class="main_box">
  18. <view class="mask_form" v-if="complete"></view>
  19. <block v-for="(item, index) in quesList.QuestionList" :key="index">
  20. <view
  21. class="ques_item_box"
  22. :id="'p' + index"
  23. :class="item.QuestType == 'SubTitle' ? 'sub_title' : ''"
  24. >
  25. <view class="ques_title_box">
  26. <text class="mustQuest_tag" wx:if="{{item.MustQuest}}">*</text>
  27. <text v-if="item.QuestType != 'SubTitle'">{{ item.Sort }}.{{ item.Question }}</text>
  28. <text v-if="item.QuestType == 'SubTitle'">{{ item.Num }}、{{ item.Question }}</text>
  29. </view>
  30. <!-- 填空题 -->
  31. <view
  32. class="ques_options align_items_left displayFlexCol"
  33. v-if="item.QuestType == 'Input'"
  34. >
  35. <text class="input_label">{{ item.Question }}:</text>
  36. <view class="textarea_box">
  37. <textarea
  38. auto-height
  39. :data-index="index"
  40. :placeholder="'最多输入' + item.RuleInfo.MaxLength + '个字'"
  41. :maxlength="item.RuleInfo.MaxLength"
  42. :value="item.AnswerList"
  43. @blur="setVal"
  44. />
  45. </view>
  46. </view>
  47. <!-- 矩阵填空题 -->
  48. <view
  49. class="ques_options align_items_left displayFlexCol"
  50. v-if="item.QuestType == 'MatrixInput'"
  51. >
  52. <block
  53. v-for="(childItem, childIndex) in item.MatrixQuestionList"
  54. :key="`MatrixInput-${index}-${childIndex}`"
  55. >
  56. <view class="matrix_input_box margin_bottom_10 displayFlexRow">
  57. <text>{{ childItem.Question }}:</text>
  58. <view class="textarea_box matrix_textarea_box">
  59. <textarea
  60. auto-height
  61. :data-index="index"
  62. :data-childindex="childIndex"
  63. :placeholder="'最多输入' + childItem.RuleInfo.MaxLength + '个字'"
  64. :maxlength="childItem.RuleInfo.MaxLength"
  65. :value="childItem.AnswerList"
  66. @input="setVal"
  67. />
  68. </view>
  69. </view>
  70. </block>
  71. </view>
  72. <!-- 单选/多选题 -->
  73. <view
  74. class="ques_options displayFlexCol"
  75. v-if="item.QuestType == 'Radio' || item.QuestType == 'Checkbox'"
  76. >
  77. <block
  78. v-for="(childItem, childIndex) in item.QuestionItemList"
  79. :key="`Checkbox-${index}-${childIndex}`"
  80. >
  81. <text
  82. class="choice_item"
  83. :class="fn.answer(item, childItem.ItemId) ? 'active_option' : ''"
  84. :data-index="index"
  85. :data-childindex="childIndex"
  86. @click="choiceOption"
  87. >
  88. {{ childItem.ItemName }}
  89. </text>
  90. </block>
  91. </view>
  92. <!-- 选择题 -->
  93. <view class="ques_options displayFlexCol" v-if="item.QuestType == 'Select'">
  94. <picker
  95. class="picker_box"
  96. range-key="ItemName"
  97. :range="item.QuestionItemList"
  98. :data-index="index"
  99. :value="item.AnswerList"
  100. @change="bindPickerChange"
  101. >
  102. <view class="picker displayFlexRow">
  103. <text>{{ item.QuestionItemList[item.AnswerList].ItemName }}</text>
  104. <image :src="icon.satisfaction.right" mode="" />
  105. </view>
  106. </picker>
  107. </view>
  108. <!-- 矩阵单选题/矩阵多选题/矩阵量表 -->
  109. <view
  110. class="ques_options matrix_border displayFlexCol"
  111. v-if="
  112. item.QuestType == 'MatrixRadio' ||
  113. item.QuestType == 'MatrixCheckbox' ||
  114. item.QuestType == 'MatrixScale'
  115. "
  116. >
  117. <view class="matrix_options matrix_options_title displayFlexRow">
  118. <block
  119. v-for="(childItem, childIndex) in item.MatrixQuestionList[0].QuestionItemList"
  120. :key="`${item.QuestType}0-${index}-${childIndex}`"
  121. >
  122. <text
  123. :style="{
  124. width: fn.getWidth(item.MatrixQuestionList[0].QuestionItemList.length) + '%',
  125. }"
  126. >
  127. {{ childItem.ItemName }}
  128. </text>
  129. </block>
  130. </view>
  131. <block
  132. v-for="(childItem, childIndex) in item.MatrixQuestionList"
  133. :key="`${item.QuestType}-${index}-${childIndex}`"
  134. >
  135. <view class="matrix_icon_box displayFlexCol">
  136. <text
  137. :style="{
  138. width: fn.getWidth(item.MatrixQuestionList[0].QuestionItemList.length) + '%',
  139. }"
  140. >{{ childItem.Question }}</text
  141. >
  142. <view class="matrix_options displayFlexBetween">
  143. <block
  144. v-for="(sunItem, sunIndex) in childItem.QuestionItemList"
  145. :key="`${item.QuestType}-${index}-${childIndex}-${sunIndex}`"
  146. >
  147. <view
  148. class="displayFlexRow"
  149. :data-index="index"
  150. :data-childindex="childIndex"
  151. :data-sunindex="sunIndex"
  152. @click="choiceMatrixOption"
  153. >
  154. <!-- 矩阵单选/矩阵量表 -->
  155. <image
  156. :src="
  157. fn.answer(childItem, sunItem.ItemId)
  158. ? icon.satisfaction.circle_active
  159. : icon.satisfaction.circle
  160. "
  161. mode=""
  162. v-if="item.QuestType == 'MatrixRadio' || item.QuestType == 'MatrixScale'"
  163. />
  164. <!-- 矩阵多选 -->
  165. <image
  166. :src="
  167. fn.answer(childItem, sunItem.ItemId)
  168. ? icon.satisfaction.checkBox_circle_active
  169. : icon.satisfaction.checkBox_circle
  170. "
  171. mode=""
  172. v-if="item.QuestType == 'MatrixCheckbox'"
  173. />
  174. </view>
  175. </block>
  176. </view>
  177. </view>
  178. </block>
  179. </view>
  180. <!-- 上传文件题 -->
  181. <view class="ques_options displayFlexCol" v-if="item.QuestType == 'UploadImage'">
  182. <view class="img_list displayFlexRow">
  183. <image
  184. class="add_img"
  185. mode=""
  186. :src="icon.satisfaction.add"
  187. :data-index="index"
  188. @click="choiceFile"
  189. />
  190. <block
  191. v-for="(imgItem, imgIndex) in item.AnswerList"
  192. :key="`UploadImage-${index}-${imgIndex}`"
  193. >
  194. <view class="add_img">
  195. <image class="item_img" :src="imgItem" mode="" />
  196. <image
  197. class="cha_img"
  198. :src="icon.satisfaction.cha_green"
  199. mode=""
  200. :data-index="index"
  201. :data-imgitem="imgItem"
  202. @click="closeImg"
  203. />
  204. </view>
  205. </block>
  206. </view>
  207. <view class="add_img_tips p_flexStart">
  208. <text>限制:</text>
  209. <text> 仅支持图片上传、</text>
  210. <text>
  211. 大小不超过{{ item.RuleInfo.FileSize }}M数量不超过{{ item.RuleInfo.FileCount }}个
  212. </text>
  213. </view>
  214. </view>
  215. <!-- 量表题 -->
  216. <view class="ques_options displayFlexRow" v-if="item.QuestType == 'Scale'">
  217. <block
  218. v-for="(childItem, childIndex) in item.QuestionItemList"
  219. :key="`Scale-${index}-${childIndex}`"
  220. >
  221. <view
  222. class="options_item_box displayFlexCol"
  223. :data-index="index"
  224. :data-childindex="childIndex"
  225. @click="choiceOption"
  226. >
  227. <text>{{ childItem.ItemName }}</text>
  228. <image
  229. :src="
  230. fn.answer(item, childItem.ItemId)
  231. ? icon.satisfaction.circle_active
  232. : icon.satisfaction.circle
  233. "
  234. mode=""
  235. />
  236. </view>
  237. </block>
  238. </view>
  239. </view>
  240. </block>
  241. </view>
  242. </scroll-view>
  243. <view class="yjfl" @click="yjfk">
  244. <image :src="icon.satisfaction.yjfk" alt="" style="width: 140rpx; height: 140rpx" />
  245. <view class="title"> 意见反馈 </view>
  246. </view>
  247. <view class="footer_box displayFlexRow">
  248. <text :class="complete ? 'backgroundCustom_D9' : ''" @click="submit">提交</text>
  249. </view>
  250. <!-- 是否实名弹窗 -->
  251. <view class="modal_wrap" v-if="showModal_Anonymous">
  252. <view class="modal_box">
  253. <view class="modal_tit">是否实名填写</view>
  254. <view class="modal_con">
  255. <view class="modal_box_b1" @click="isAnonymous(1)">实名填写</view>
  256. <view class="modal_box_b1" @click="isAnonymous(2)">匿名填写</view>
  257. </view>
  258. </view>
  259. </view>
  260. <!-- 是否实名弹窗 -->
  261. <view class="modal_wrap" v-if="showModal_User">
  262. <view class="modal_box">
  263. <view class="modal_tit">请选择答卷人</view>
  264. <view class="modal_con">
  265. <view class="modal_user_item" v-if="currentUser.memberName" @click="goSelMember">
  266. <view>
  267. <view>
  268. <text class="modal_t1">{{ currentUser.memberName }}</text>
  269. <text class="modal_t2">
  270. {{ currentUser.sex == 1 ? '男' : currentUser.sex == 2 ? '女' : '未知' }} |
  271. {{ currentUser.age }}岁
  272. </text>
  273. </view>
  274. <view class="modal_t3">{{ currentUser.mobile }}</view>
  275. </view>
  276. <image class="modal_user_right_img" :src="icon.satisfaction.right"></image>
  277. </view>
  278. <view class="modal_user_item" wx:else @click="goSelMember">
  279. <view>点击选择答卷人</view>
  280. <image class="modal_user_right_img" :src="icon.satisfaction.right"></image>
  281. </view>
  282. <view class="modal_btn_wrap displayFlexBetween" v-if="currentUser.memberName">
  283. <view class="modal_btn modal_btn1" @click="goBack">取消</view>
  284. <view class="modal_btn modal_btn2" @click="confirmMember">确定</view>
  285. </view>
  286. </view>
  287. </view>
  288. </view>
  289. </view>
  290. </template>
  291. <script lang="ts" setup>
  292. import { reactive, ref } from 'vue';
  293. import { useOnLoad } from '@/hook';
  294. import { useDomain } from '@kasite/uni-app-base';
  295. import { mapGetters } from '@kasite/uni-app-base/store/hook';
  296. import {
  297. QuerySubjectListToChannelTask_V3,
  298. QuerySubjectInfoById_V3,
  299. UploadZxFile,
  300. CommitAnswer_V3,
  301. } from '../../service';
  302. import icon from '@/utils/icon';
  303. import { common } from '@/utils';
  304. import fn from './fn';
  305. const app = getApp();
  306. let time = null;
  307. const currentUser = ref({} as any);
  308. const taskId = ref('');
  309. const objType = ref('3'); // 3门诊 4住院
  310. const quesList = ref({} as any);
  311. const imgList = ref([]);
  312. const point = ref('');
  313. const complete = ref(false);
  314. const anonymousType = ref(0);
  315. const showModal_Anonymous = ref(false); // 是否实名填写弹窗显示
  316. const showModal_User = ref(false); // 实名用户选择弹窗显示
  317. let quesAnswers = reactive({
  318. MemberId: '',
  319. TaskId: '-1',
  320. SysAppId: 'visit',
  321. SubjectId: '',
  322. UserAgent: '',
  323. IP: '',
  324. Location: '',
  325. Mobile: '',
  326. UserName: '',
  327. Sex: '',
  328. Age: '',
  329. ThirdPartyId: '',
  330. AnswerUseTime: 0,
  331. PushDept: '',
  332. PushDeptName: '',
  333. BedNo: '',
  334. HospitalNo: '',
  335. CardNo: '',
  336. AnswerList: [],
  337. });
  338. const { getCurrentUser } = mapGetters({
  339. getCurrentUser: 'getCurrentUser',
  340. });
  341. const main = async (options) => {
  342. currentUser.value = getCurrentUser();
  343. const params = {
  344. SubjectId: options.subjectId,
  345. TaskId: options.taskId,
  346. };
  347. const resp = await QuerySubjectListToChannelTask_V3(params);
  348. if (!common.isEmpty(resp)) {
  349. objType.value = resp[0].GroupType;
  350. //匿名有3种传参 ""(空) "true" "false" 转换字符串为布尔值
  351. let anonymous =
  352. resp[0].Anonymous === 'false'
  353. ? false
  354. : resp[0].Anonymous === 'true'
  355. ? true
  356. : resp[0].Anonymous || '';
  357. // type 1实名 2:匿名 3自行选择
  358. anonymousType.value = anonymous === '' ? 3 : anonymous === false ? 1 : 2;
  359. showModal_Anonymous.value = anonymous == 3 ? true : false;
  360. taskId.value = options.taskId;
  361. quesAnswers.SubjectId = options.subjectId;
  362. //如果不是执行选择直接调用对应填写按钮
  363. if (anonymous != 3) {
  364. isAnonymous(anonymous);
  365. }
  366. querySubjectInfoById_V3();
  367. // 开始计算答卷时间
  368. getSec();
  369. } else {
  370. common.showModal('该任务已失效', () => {
  371. common.goToUrl(`/pages/business/tabbar/homePage/homePage`, { skipWay: 'reLaunch' });
  372. });
  373. return;
  374. }
  375. };
  376. /** 实名/匿名 */
  377. const isAnonymous = (type) => {
  378. //实名
  379. if (type == 1) {
  380. showModal_Anonymous.value = false;
  381. showModal_User.value = true;
  382. }
  383. //匿名
  384. else {
  385. currentUser.value = {};
  386. showModal_Anonymous.value = false;
  387. }
  388. };
  389. /** 问卷详情 */
  390. const querySubjectInfoById_V3 = async () => {
  391. const resp = await QuerySubjectInfoById_V3({
  392. SubjectId: quesAnswers.SubjectId,
  393. });
  394. if (common.isNotEmpty(resp)) {
  395. if (resp[0].Status != 0) {
  396. common.showModal('该问卷已失效', () => {
  397. common.navigateBack(1);
  398. });
  399. return;
  400. }
  401. if (resp[0].State != 1) {
  402. common.showModal('该问卷未发布', () => {
  403. common.navigateBack(1);
  404. });
  405. return;
  406. }
  407. // 提交答案数据模版
  408. quesAnswers.PushDept = resp[0].DeptId;
  409. quesAnswers.PushDeptName = resp[0].PushDeptName;
  410. resp[0].QuestionList.forEach((item, index) => {
  411. item.AnswerList = [];
  412. item.MustQuest = item.MustQuest == 'false' ? false : true;
  413. item.RuleInfo = item.RuleInfo != '' ? JSON.parse(item.RuleInfo) : '';
  414. // 多选框
  415. if (item.QuestType == 'Select') {
  416. item.AnswerList = 0;
  417. }
  418. if (common.isNotEmpty(item.MatrixQuestionList)) {
  419. item.MatrixQuestionList.forEach((childItem) => {
  420. childItem.AnswerList = [];
  421. childItem.RuleInfo = childItem.RuleInfo != '' ? JSON.parse(childItem.RuleInfo) : '';
  422. // 答案列表模版
  423. let answerItem = {
  424. Answer: [],
  425. Blank: index,
  426. QuestId: childItem.QuestId,
  427. QuestType: item.QuestType,
  428. MustQuest: item.MustQuest,
  429. };
  430. quesAnswers.AnswerList.push(answerItem);
  431. if (common.isNotEmpty(childItem.QuestionItemList)) {
  432. childItem.QuestionItemList.forEach((sunItem) => {
  433. sunItem.Check = false;
  434. });
  435. }
  436. });
  437. } else {
  438. // 答案列表模版
  439. let answerItem = {
  440. Answer: [],
  441. Blank: index,
  442. QuestId: item.QuestId,
  443. QuestType: item.QuestType,
  444. MustQuest: item.MustQuest,
  445. };
  446. quesAnswers.AnswerList.push(answerItem);
  447. }
  448. });
  449. resp[0].QuestionList = bySort(resp[0].QuestionList);
  450. quesList.value = resp[0];
  451. console.log(quesList.value);
  452. }
  453. };
  454. /** 计算答题时间 */
  455. const getSec = () => {
  456. time = setTimeout(() => {
  457. let answerUseTime = quesAnswers.AnswerUseTime;
  458. answerUseTime++;
  459. quesAnswers.AnswerUseTime = answerUseTime;
  460. getSec();
  461. }, 1000);
  462. };
  463. /** 根据子标题排序 */
  464. const bySort = (list: any[]) => {
  465. let find = 0;
  466. let sort = 0;
  467. let item = {} as any;
  468. for (var t = 0; t < list.length; t++) {
  469. item = list[t];
  470. //子标题
  471. if (item.QuestType == 'SubTitle') {
  472. //将子标题底下的题目从1开始排
  473. sort = 0;
  474. //判断是出现的第几个子标题
  475. //num是子标题的排序
  476. item.Num = toChinesNum(find + 1);
  477. find++;
  478. } else {
  479. //sort是子标题底下的排序
  480. item.Sort = sort + 1;
  481. sort++;
  482. }
  483. item.SortNum = t;
  484. if (common.isNotEmpty(item.QuestionItemList)) {
  485. item.QuestionItemList.forEach((childItem, childIndex) => {
  486. childItem.SortNum = childIndex;
  487. if (common.isNotEmpty(childItem.QuestionItem)) {
  488. childItem.QuestionItem.forEach((sunItem, sunIndex) => {
  489. sunItem.SortNum = sunIndex;
  490. });
  491. }
  492. });
  493. }
  494. }
  495. return list;
  496. };
  497. /** 汉字顺序 */
  498. const toChinesNum = (num) => {
  499. var changeNum = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十'],
  500. newNum = '',
  501. arr = num.toString().split('');
  502. arr[0] = parseInt(arr[0]) - 1;
  503. if (arr[0] == -1 && arr.length == 1) {
  504. return '零';
  505. }
  506. if (arr.length > 1) {
  507. arr[1] = parseInt(arr[1]) - 1;
  508. if (!arr[0]) {
  509. newNum = !arr[0] && arr[1] == -1 ? changeNum[9] : changeNum[9] + changeNum[arr[1]];
  510. } else {
  511. newNum = changeNum[arr[0]] + changeNum[9] + (changeNum[arr[1]] ? changeNum[arr[1]] : '');
  512. }
  513. } else {
  514. newNum = changeNum[arr[0]];
  515. }
  516. return newNum;
  517. };
  518. /** 单选/多选/量表 */
  519. const choiceOption = (e) => {
  520. let index = e.currentTarget.dataset.index;
  521. let childIndex = e.currentTarget.dataset.childindex;
  522. let answerIndex = 0;
  523. let questionList = quesList.value.QuestionList;
  524. let answerList = quesAnswers.AnswerList;
  525. answerList.forEach((itm, ind) => {
  526. if (itm.QuestId == questionList[index].QuestId) {
  527. answerIndex = ind;
  528. }
  529. });
  530. // 单选/量表
  531. if (questionList[index].QuestType == 'Radio' || questionList[index].QuestType == 'Scale') {
  532. if (
  533. questionList[index].AnswerList[0] != questionList[index].QuestionItemList[childIndex].ItemId
  534. ) {
  535. questionList[index].AnswerList = [];
  536. questionList[index].AnswerList.push(questionList[index].QuestionItemList[childIndex].ItemId);
  537. }
  538. answerList[answerIndex].Answer = questionList[index].QuestionItemList[childIndex].ItemId;
  539. }
  540. // 多选
  541. else if (questionList[index].QuestType == 'Checkbox') {
  542. let flag = false;
  543. questionList[index].AnswerList.forEach((item) => {
  544. if (item == questionList[index].QuestionItemList[childIndex].ItemId) {
  545. flag = true;
  546. }
  547. });
  548. if (flag) {
  549. questionList[index].AnswerList = questionList[index].AnswerList.filter((item) => {
  550. return item != questionList[index].QuestionItemList[childIndex].ItemId;
  551. });
  552. answerList[answerIndex].Answer = answerList[answerIndex].Answer.filter((fiItem) => {
  553. return fiItem != questionList[index].QuestionItemList[childIndex].ItemId;
  554. });
  555. } else {
  556. if (questionList[index].RuleInfo.MaxLength < questionList[index].AnswerList.length + 1) {
  557. common.showModal('最多选择' + questionList[index].RuleInfo.MaxLength + '项');
  558. return;
  559. }
  560. questionList[index].AnswerList.push(questionList[index].QuestionItemList[childIndex].ItemId);
  561. answerList[answerIndex].Answer.push(questionList[index].QuestionItemList[childIndex].ItemId);
  562. }
  563. }
  564. quesList.value.QuestionList = questionList;
  565. quesAnswers.AnswerList = answerList;
  566. };
  567. /** 选择题 */
  568. const bindPickerChange = (e) => {
  569. let index = e.currentTarget.dataset.index;
  570. let val = e.detail.value;
  571. let questionList = quesList.value.QuestionList;
  572. let answerList = quesAnswers.AnswerList;
  573. let answerIndex = 0;
  574. answerList.forEach((itm, ind) => {
  575. if (itm.QuestId == questionList[index].QuestId) {
  576. answerIndex = ind;
  577. }
  578. });
  579. questionList[index].AnswerList = val;
  580. answerList[answerIndex].Answer = questionList[index].QuestionItemList[val].ItemId;
  581. quesList.value.QuestionList = questionList;
  582. quesAnswers.AnswerList = answerList;
  583. };
  584. /** 矩阵单选 */
  585. const choiceMatrixOption = (e) => {
  586. let index = e.currentTarget.dataset.index;
  587. let childIndex = e.currentTarget.dataset.childindex;
  588. let sunIndex = e.currentTarget.dataset.sunindex;
  589. let questionList = quesList.value.QuestionList;
  590. let answerList = quesAnswers.AnswerList;
  591. let answerIndex = 0;
  592. answerList.forEach((itm, ind) => {
  593. if (itm.QuestId == questionList[index].MatrixQuestionList[childIndex].QuestId) {
  594. answerIndex = ind;
  595. }
  596. });
  597. // 矩阵单选/矩阵量表
  598. if (
  599. questionList[index].QuestType == 'MatrixRadio' ||
  600. questionList[index].QuestType == 'MatrixScale'
  601. ) {
  602. if (
  603. questionList[index].MatrixQuestionList[childIndex].AnswerList[0] !=
  604. questionList[index].MatrixQuestionList[childIndex].QuestionItemList[sunIndex].ItemId
  605. ) {
  606. questionList[index].MatrixQuestionList[childIndex].AnswerList = [];
  607. questionList[index].MatrixQuestionList[childIndex].AnswerList.push(
  608. questionList[index].MatrixQuestionList[childIndex].QuestionItemList[sunIndex].ItemId
  609. );
  610. }
  611. answerList[answerIndex].Answer =
  612. questionList[index].MatrixQuestionList[childIndex].QuestionItemList[sunIndex].ItemId;
  613. }
  614. // 矩阵多选
  615. else if (questionList[index].QuestType == 'MatrixCheckbox') {
  616. let flag = false;
  617. questionList[index].MatrixQuestionList[childIndex].AnswerList.forEach((item) => {
  618. if (
  619. item == questionList[index].MatrixQuestionList[childIndex].QuestionItemList[sunIndex].ItemId
  620. ) {
  621. flag = true;
  622. }
  623. });
  624. if (flag) {
  625. questionList[index].MatrixQuestionList[childIndex].AnswerList = questionList[
  626. index
  627. ].MatrixQuestionList[childIndex].AnswerList.filter((item) => {
  628. return (
  629. item !=
  630. questionList[index].MatrixQuestionList[childIndex].QuestionItemList[sunIndex].ItemId
  631. );
  632. });
  633. answerList[answerIndex].Answer = answerList[answerIndex].Answer.filter((fiItem) => {
  634. return (
  635. fiItem !=
  636. questionList[index].MatrixQuestionList[childIndex].QuestionItemList[sunIndex].ItemId
  637. );
  638. });
  639. } else {
  640. questionList[index].MatrixQuestionList[childIndex].AnswerList.push(
  641. questionList[index].MatrixQuestionList[childIndex].QuestionItemList[sunIndex].ItemId
  642. );
  643. answerList[answerIndex].Answer.push(
  644. questionList[index].MatrixQuestionList[childIndex].QuestionItemList[sunIndex].ItemId
  645. );
  646. }
  647. }
  648. quesList.value.QuestionList = questionList;
  649. quesAnswers.AnswerList = answerList;
  650. };
  651. /** 选择文件 */
  652. const choiceFile = (e) => {
  653. let index = e.currentTarget.dataset.index;
  654. let questionList = quesList.value.QuestionList;
  655. let answerList = quesAnswers.AnswerList;
  656. let answerIndex = 0;
  657. answerList.forEach((itm, ind) => {
  658. if (itm.QuestId == questionList[index].QuestId) {
  659. answerIndex = ind;
  660. }
  661. });
  662. if (answerList[answerIndex].Answer.length >= questionList[index].RuleInfo.FileCount) {
  663. common.showModal('最多上传' + questionList[index].RuleInfo.FileCount + '张图片');
  664. return;
  665. }
  666. uni.chooseMedia({
  667. count: questionList[index].RuleInfo.FileCount,
  668. mediaType: ['image'],
  669. sourceType: ['album', 'camera'],
  670. sizeType: ['compressed'],
  671. async success(res) {
  672. uni.showLoading({
  673. title: '上传中。。。',
  674. });
  675. for (var i = 0; i < res.tempFiles.length; i++) {
  676. let m = 1024 * 1024;
  677. if (res.tempFiles[i].size < m) {
  678. let imgUrl = (await uploadFile(
  679. res.tempFiles[i].tempFilePath,
  680. questionList[index].RuleInfo.FileCount,
  681. answerList[answerIndex].Answer
  682. )) as string;
  683. if (common.isNotEmpty(imgUrl)) {
  684. imgUrl =
  685. imgUrl.indexOf('http') > -1 ? imgUrl : useDomain() + imgUrl.replace(/\\/g, '/');
  686. answerList[answerIndex].Answer.push(imgUrl);
  687. questionList[index].AnswerList = answerList[answerIndex].Answer;
  688. quesList.value.QuestionList = questionList;
  689. quesAnswers.AnswerList = answerList;
  690. if (res.tempFiles.length - 1 == i) {
  691. uni.hideLoading();
  692. }
  693. }
  694. } else {
  695. uni.hideLoading();
  696. common.showModal('文件不得大于' + questionList[index].RuleInfo.FileSize + 'M');
  697. return;
  698. }
  699. }
  700. },
  701. });
  702. };
  703. /** 上传文件 */
  704. const uploadFile = (imgItem, fileCount, imgList) => {
  705. return new Promise((resolve, reject) => {
  706. if (imgList.length >= fileCount) {
  707. uni.hideLoading();
  708. common.showModal('最多上传' + fileCount + '张图片');
  709. return;
  710. }
  711. // 将图片上传至服务器
  712. uni.uploadFile({
  713. url: UploadZxFile,
  714. filePath: imgItem,
  715. name: 'newsFile',
  716. formData: {
  717. user: 'test',
  718. },
  719. header: {
  720. token: uni.getStorageSync('token'),
  721. },
  722. data: {},
  723. success(res) {
  724. const data = JSON.parse(res.data);
  725. if (data.RespCode == '10000') {
  726. resolve(data.url);
  727. } else {
  728. common.showModal(data.msg);
  729. }
  730. },
  731. });
  732. });
  733. };
  734. /** 删除图片 */
  735. const closeImg = (e) => {
  736. let index = e.currentTarget.dataset.index;
  737. let imgItem = e.currentTarget.dataset.imgitem;
  738. let questionList = quesList.value.QuestionList;
  739. let answerList = quesAnswers.AnswerList;
  740. let answerIndex = 0;
  741. answerList.forEach((itm, ind) => {
  742. if (itm.QuestId == questionList[index].QuestId) {
  743. answerIndex = ind;
  744. }
  745. });
  746. answerList[answerIndex].Answer = answerList[answerIndex].Answer.filter((item) => {
  747. return item != imgItem;
  748. });
  749. questionList[index].AnswerList = answerList[answerIndex].Answer;
  750. quesList.value.QuestionList = questionList;
  751. quesAnswers.AnswerList = answerList;
  752. };
  753. /** 获取input值 */
  754. const setVal = (e) => {
  755. let index = e.currentTarget.dataset.index;
  756. let childIndex = e.currentTarget.dataset.childindex;
  757. let questionList = quesList.value.QuestionList;
  758. let answerList = quesAnswers.AnswerList;
  759. let answerIndex = 0;
  760. // 矩阵填空题
  761. if (questionList[index].QuestType == 'MatrixInput') {
  762. if (
  763. questionList[index].MatrixQuestionList[childIndex].AnswerList.length ==
  764. questionList[index].MatrixQuestionList[childIndex].RuleInfo.MaxLength
  765. ) {
  766. common.showToast(
  767. '最多输入' + questionList[index].MatrixQuestionList[childIndex].RuleInfo.MaxLength + '个字'
  768. );
  769. return;
  770. }
  771. answerList.forEach((itm, ind) => {
  772. if (itm.QuestId == questionList[index].MatrixQuestionList[childIndex].QuestId) {
  773. answerIndex = ind;
  774. }
  775. });
  776. questionList[index].MatrixQuestionList[childIndex].AnswerList = e.detail.value;
  777. }
  778. // 填空题
  779. else {
  780. if (questionList[index].RuleInfo.DataType != '无') {
  781. let dataTypeOptions = questionList[index].RuleInfo.DataTypeOptions;
  782. for (var i = 0; i < dataTypeOptions.length; i++) {
  783. if (questionList[index].RuleInfo.DataType == dataTypeOptions[i].Value) {
  784. const regRule = dataTypeOptions[i].Rule;
  785. let reg = null;
  786. if (regRule.startsWith('/') && regRule.endsWith('/')) {
  787. reg = new RegExp(regRule.slice(1, -1));
  788. } else {
  789. reg = new RegExp(regRule);
  790. }
  791. if (!reg.test(e.detail.value)) {
  792. common.showModal('请输入' + dataTypeOptions[i].Text);
  793. questionList[index].AnswerList = '';
  794. answerList[answerIndex].Answer = '';
  795. this.setData({
  796. 'quesList.QuestionList': questionList,
  797. 'quesAnswers.AnswerList': answerList,
  798. });
  799. return;
  800. }
  801. }
  802. }
  803. }
  804. if (questionList[index].AnswerList.length == questionList[index].RuleInfo.MaxLength) {
  805. common.showToast('最多输入' + questionList[index].RuleInfo.MaxLength + '个字');
  806. return;
  807. }
  808. answerList.forEach((itm, ind) => {
  809. if (itm.QuestId == questionList[index].QuestId) {
  810. answerIndex = ind;
  811. }
  812. });
  813. questionList[index].AnswerList = e.detail.value;
  814. }
  815. answerList[answerIndex].Answer = e.detail.value;
  816. quesList.value.QuestionList = questionList;
  817. quesAnswers.AnswerList = answerList;
  818. };
  819. /** 提交 */
  820. const submit = async () => {
  821. uni.showLoading();
  822. await common.sleep(1000);
  823. if (complete.value) return;
  824. const answers = { ...quesAnswers } as any;
  825. for (var i = 0; i < answers.AnswerList.length; i++) {
  826. let item = answers.AnswerList[i];
  827. if (item.MustQuest && common.isEmpty(item.Answer)) {
  828. common.showToast('存在未填写的问卷');
  829. point.value = 'p' + item.Blank;
  830. return;
  831. }
  832. }
  833. answers.AnswerList.forEach((item) => {
  834. if (typeof item.Answer == 'object') {
  835. item.Answer = item.Answer.join();
  836. }
  837. });
  838. answers.AnswerList = JSON.stringify(quesAnswers.AnswerList);
  839. quesAnswers.IP = (await getIP()).cip;
  840. quesAnswers.Location = (await getIP()).cname;
  841. quesAnswers.UserAgent = app.globalData.smallPro_systemInfo;
  842. quesAnswers.Mobile = currentUser.value.mobile;
  843. quesAnswers.UserName = currentUser.value.memberName;
  844. quesAnswers.MemberId = currentUser.value.memberId;
  845. quesAnswers.Sex = currentUser.value.sex;
  846. quesAnswers.Age = currentUser.value.age;
  847. quesAnswers.ThirdPartyId = currentUser.value.memberId || uni.getStorageSync('openid');
  848. quesAnswers.BedNo = '';
  849. quesAnswers.HospitalNo = objType.value == '4' ? currentUser.value.cardNo : '';
  850. quesAnswers.CardNo = objType.value == '3' ? currentUser.value.cardNo : '';
  851. quesAnswers.TaskId = taskId.value;
  852. let res = await CommitAnswer_V3(quesAnswers);
  853. clearTimeout(time);
  854. if (common.isNotEmpty(res)) {
  855. common.showModal('提交成功!', () => {
  856. common.navigateBack(1);
  857. });
  858. }
  859. };
  860. /** 获取IP */
  861. const getIP = () => {
  862. return new Promise((resolve, reject) => {
  863. uni.request({
  864. url: 'https://pv.sohu.com/cityjson?ie=utf-8',
  865. success: (res: any) => {
  866. const result = res.data.substring(res.data.indexOf('{'), res.data.lastIndexOf('}') + 1);
  867. const obj = JSON.parse(result);
  868. resolve(obj);
  869. },
  870. });
  871. }) as Promise<any>;
  872. };
  873. const goBack = () => {
  874. uni.navigateBack({
  875. delta: 1,
  876. });
  877. };
  878. const yjfk = () => {};
  879. const goSelMember = () => {};
  880. const confirmMember = () => {};
  881. useOnLoad((options) => {
  882. main(options);
  883. });
  884. </script>
  885. <style lang="scss" scoped>
  886. .align_items_left {
  887. align-items: flex-start;
  888. }
  889. .active_option {
  890. background: #18ba89 !important;
  891. color: white !important;
  892. }
  893. .mask_form {
  894. width: 100%;
  895. height: 100%;
  896. position: absolute;
  897. top: 0;
  898. left: 0;
  899. z-index: 100;
  900. }
  901. .container {
  902. overflow: hidden;
  903. }
  904. .scroll_view {
  905. height: 100%;
  906. }
  907. .top_bg_box {
  908. position: relative;
  909. image {
  910. width: 100%;
  911. height: 456rpx;
  912. position: absolute;
  913. top: 0;
  914. left: 0;
  915. z-index: 1;
  916. }
  917. .ques_introduce {
  918. padding: 46rpx 52rpx 0 52rpx;
  919. box-sizing: border-box;
  920. position: absolute;
  921. top: 0;
  922. left: 0;
  923. z-index: 2;
  924. text:nth-child(1) {
  925. font-size: 36rpx;
  926. font-weight: bold;
  927. color: white;
  928. margin-bottom: 20rpx;
  929. }
  930. text:nth-child(2) {
  931. line-height: 45rpx;
  932. font-size: 28rpx;
  933. color: white;
  934. }
  935. }
  936. }
  937. .main_box {
  938. padding: 470rpx 30rpx 190rpx 30rpx;
  939. box-sizing: border-box;
  940. position: relative;
  941. z-index: 2;
  942. }
  943. .ques_item_box {
  944. padding: 30rpx;
  945. box-sizing: border-box;
  946. background: white;
  947. border-radius: 20rpx;
  948. margin-bottom: 32rpx;
  949. > .ques_title_box > text {
  950. line-height: 50rpx;
  951. font-size: 36rpx;
  952. font-weight: bold;
  953. color: #1c1c1c;
  954. }
  955. .mustQuest_tag {
  956. color: #dc2828;
  957. }
  958. }
  959. .ques_options {
  960. margin-top: 34rpx;
  961. }
  962. .choice_item {
  963. width: 100%;
  964. line-height: 80rpx;
  965. font-size: 30rpx;
  966. color: #686868;
  967. text-align: center;
  968. margin-bottom: 16rpx;
  969. border-radius: 10rpx;
  970. background: #f8f8fa;
  971. &:last-child {
  972. margin-bottom: 0;
  973. }
  974. }
  975. .input_label {
  976. line-height: 40rpx;
  977. font-size: 32rpx;
  978. color: #474747;
  979. }
  980. .textarea_box {
  981. width: 100%;
  982. padding: 20rpx;
  983. box-sizing: border-box;
  984. border-radius: 10rpx;
  985. background: #f8f8fa;
  986. margin-top: 22rpx;
  987. textarea {
  988. width: 100%;
  989. }
  990. }
  991. .matrix_textarea_box {
  992. width: 70%;
  993. }
  994. .picker_box {
  995. width: 100%;
  996. }
  997. .picker {
  998. width: 100%;
  999. height: 80rpx;
  1000. padding: 22rpx;
  1001. box-sizing: border-box;
  1002. background: #f9f9f9;
  1003. border-radius: 20rpx;
  1004. justify-content: space-between;
  1005. text {
  1006. white-space: nowrap;
  1007. font-size: 28rpx;
  1008. color: #686868;
  1009. }
  1010. image {
  1011. width: 12rpx;
  1012. height: 24rpx;
  1013. }
  1014. }
  1015. .matrix_options {
  1016. width: 100%;
  1017. margin-bottom: 34rpx;
  1018. justify-content: space-between;
  1019. text {
  1020. font-size: 30rpx;
  1021. color: #1c1c1c;
  1022. text-align: center;
  1023. padding: 20rpx;
  1024. box-sizing: border-box;
  1025. word-wrap: break-word;
  1026. word-break: break-all;
  1027. }
  1028. }
  1029. .matrix_border {
  1030. border: 1px solid #f0f0f0;
  1031. }
  1032. .matrix_options_title {
  1033. background: #f5f5f5;
  1034. }
  1035. .matrix_icon_box {
  1036. width: 100%;
  1037. align-items: flex-start;
  1038. text {
  1039. font-size: 30rpx;
  1040. color: #1c1c1c;
  1041. margin-bottom: 36rpx;
  1042. padding: 0 20rpx;
  1043. box-sizing: border-box;
  1044. }
  1045. image {
  1046. width: 40rpx;
  1047. height: 40rpx;
  1048. }
  1049. }
  1050. .sub_title {
  1051. background: none;
  1052. }
  1053. .img_list {
  1054. width: 100%;
  1055. margin-bottom: 24rpx;
  1056. justify-content: flex-start;
  1057. flex-wrap: wrap;
  1058. .item_img {
  1059. width: 100%;
  1060. height: 100%;
  1061. }
  1062. }
  1063. .add_img {
  1064. width: 32%;
  1065. height: 200rpx;
  1066. margin-right: 2%;
  1067. margin-bottom: 3%;
  1068. position: relative;
  1069. &:nth-child(3n) {
  1070. margin-right: 0;
  1071. }
  1072. }
  1073. .add_img_tips {
  1074. width: 100%;
  1075. text {
  1076. font-size: 30rpx;
  1077. color: #474747;
  1078. }
  1079. }
  1080. .cha_img {
  1081. width: 50rpx;
  1082. height: 50rpx;
  1083. position: absolute;
  1084. top: -15rpx;
  1085. right: -5rpx;
  1086. }
  1087. .options_item_box {
  1088. width: 100%;
  1089. padding: 0 10rpx;
  1090. box-sizing: border-box;
  1091. margin-bottom: 20rpx;
  1092. justify-content: space-between;
  1093. text {
  1094. font-size: 28rpx;
  1095. color: #686868;
  1096. word-wrap: break-word;
  1097. word-break: break-all;
  1098. }
  1099. image {
  1100. width: 40rpx;
  1101. height: 40rpx;
  1102. margin: 20rpx 0;
  1103. }
  1104. }
  1105. .matrix_input_box {
  1106. width: 100%;
  1107. text {
  1108. width: 30%;
  1109. white-space: nowrap;
  1110. }
  1111. input {
  1112. width: 70%;
  1113. }
  1114. }
  1115. .footer_box {
  1116. width: 100%;
  1117. padding: 30rpx 30rpx 60rpx 30rpx;
  1118. box-sizing: border-box;
  1119. background: white;
  1120. position: fixed;
  1121. bottom: 0;
  1122. left: 0;
  1123. z-index: 10;
  1124. text {
  1125. width: 100%;
  1126. line-height: 88rpx;
  1127. font-size: 36rpx;
  1128. color: white;
  1129. text-align: center;
  1130. border-radius: 88rpx;
  1131. background: #18ba89;
  1132. display: block;
  1133. }
  1134. }
  1135. .modal_wrap {
  1136. width: 100%;
  1137. height: 100%;
  1138. background-color: rgba(0, 0, 0, 0.6);
  1139. position: fixed;
  1140. left: 0;
  1141. top: 0;
  1142. z-index: 99;
  1143. display: flex;
  1144. align-items: center;
  1145. justify-content: center;
  1146. }
  1147. .modal_box {
  1148. width: 600rpx;
  1149. max-height: 600rpx;
  1150. background-color: #fff;
  1151. border-radius: 5px;
  1152. padding: 40rpx 40rpx 60rpx;
  1153. }
  1154. .modal_tit {
  1155. text-align: center;
  1156. font-size: 30rpx;
  1157. }
  1158. .modal_box_b1 {
  1159. background-color: #f2f2f2;
  1160. border-radius: 5px;
  1161. line-height: 80rpx;
  1162. margin-top: 40rpx;
  1163. /* padding-left: 40rpx; */
  1164. text-align: center;
  1165. }
  1166. .modal_user_item {
  1167. background: #f2f2f2;
  1168. padding: 30rpx;
  1169. margin-top: 40rpx;
  1170. position: relative;
  1171. }
  1172. .modal_user_right_img {
  1173. width: 12rpx;
  1174. height: 21rpx;
  1175. position: absolute;
  1176. right: 30rpx;
  1177. top: 0;
  1178. bottom: 0;
  1179. margin: auto 0;
  1180. }
  1181. .modal_t1 {
  1182. font-weight: bold;
  1183. display: inline-block;
  1184. margin-right: 20rpx;
  1185. font-size: 32rpx;
  1186. }
  1187. .modal_t3 {
  1188. margin-top: 20rpx;
  1189. }
  1190. .modal_btn {
  1191. width: 46%;
  1192. line-height: 75rpx;
  1193. text-align: center;
  1194. border-radius: 50rpx;
  1195. margin-top: 40rpx;
  1196. }
  1197. .modal_btn1 {
  1198. background: #aaaaaa;
  1199. color: #fff;
  1200. }
  1201. .modal_btn2 {
  1202. background: #61c88f;
  1203. color: #fff;
  1204. }
  1205. .yjfl {
  1206. position: fixed;
  1207. bottom: 340rpx;
  1208. right: 0;
  1209. z-index: 100;
  1210. width: 160rpx;
  1211. text-align: center;
  1212. .title {
  1213. color: #fff;
  1214. position: absolute;
  1215. bottom: 10rpx;
  1216. right: 4rpx;
  1217. width: 100%;
  1218. text-align: center;
  1219. font-size: 24rpx;
  1220. }
  1221. }
  1222. </style>