WebQn.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. <template>
  2. <div>
  3. <!-- page title -->
  4. <div v-if="stage == 0">
  5. <mt-header type="default" title="问卷调查-问候语" fixed></mt-header>
  6. </div>
  7. <div v-else-if="stage == 1">
  8. <mt-header title="问卷调查-问卷题目" fixed>
  9. <mt-button v-if="questionHEAD!=0" icon="back" slot="left" @click="onPreTap">返回</mt-button>
  10. </mt-header>
  11. </div>
  12. <div v-else-if="stage == 2">
  13. <mt-header title="问卷调查-结束语" fixed></mt-header>
  14. <p>
  15. <img src="static/ending-image.jpeg" style="width: 100%;"/>
  16. </p>
  17. </div>
  18. <!-- 问候语 -->
  19. <div v-if="stage == 0">
  20. <p style="margin: 80px 0;">{{questionaire.info.hello}}</p>
  21. <mt-button type="primary" @click="start" class="button-bottom">继续</mt-button>
  22. </div>
  23. <!-- 问卷题目 -->
  24. <div rows="auto * auto" v-else-if="stage==1">
  25. <!-- 题目问题 -->
  26. <div style="margin:20px 0 40px 0">
  27. <!-- <Progress :value="questionHEAD" :maxValue="questionaire.questions.length" /> -->
  28. <mt-progress :value="percent" :bar-height="5" style="margin-top: -30px;"></mt-progress>
  29. <div>
  30. <span class="h3">{{questionHEAD + 1}}、</span>
  31. <span class="h3" style="margin-left: 5;">[</span>
  32. <span class="h3">{{questionType}}</span>
  33. <span class="h3" style="margin-right: 5;">]</span>
  34. </div>
  35. <p class="h3">{{questionBody}}</p>
  36. <span class="h3">{{questionRemark}}</span>
  37. </div>
  38. <mt-radio
  39. v-if="questionType == '单选题'"
  40. v-model="selectedSingle"
  41. :options="questionOptions"
  42. @change="onOptionSelected"
  43. ></mt-radio>
  44. <mt-checklist
  45. v-else-if="questionType == '多选题'"
  46. v-model="selectedMultiple"
  47. :options="questionOptions"
  48. @change="onOptionSelected"
  49. ></mt-checklist>
  50. <textarea
  51. v-model="answerValue"
  52. placeholder="请在此输入答案"
  53. v-else-if="questionType == '开放题'"
  54. style="width: 96%;height: 160px;"
  55. />
  56. <mt-button
  57. type="primary"
  58. @click="onQuestionConfirm"
  59. class="button-bottom"
  60. v-show="nextBtnVisible"
  61. >继续</mt-button>
  62. </div>
  63. <!-- <div rows="* auto" v-else class="margin">
  64. <Label class="body" :text="questionaire.info.bye" textWrap="true" verticalAlignment="top" />
  65. <Button text="继续" @tap="onFinishTap" row="1" />
  66. </div>-->
  67. <div v-if="stage == 2">
  68. <p style="margin: 80px 0;">{{questionaire.info.bye}}</p>
  69. </div>
  70. </div>
  71. </template>
  72. <script>
  73. import axios from "axios";
  74. import dateFormat from "../dateFormat.js";
  75. import indicatorBiz from "../indicatorBiz.js";
  76. import Vue from "vue";
  77. import { MessageBox } from "mint-ui";
  78. // CREATED(0, "已创建"),
  79. // CLICKED(1, "已点击"),
  80. // STARTED(2, "已开始"),
  81. // COMPLETE(3, "已完成");
  82. export default {
  83. name: "WebQn",
  84. data: function() {
  85. return {};
  86. },
  87. data: function() {
  88. return {
  89. webQuestionaire: {},
  90. questionaire: { info: {} },
  91. questionHEAD: 0,
  92. answerSheet: {
  93. // questionaireId: this.questionaire.info.id,
  94. questionaireId: 0,
  95. sheetName: "",
  96. status: 0,
  97. startTime: null,
  98. endTime: null,
  99. locationLong: this.long,
  100. locationLat: this.lat
  101. },
  102. answers: {},
  103. answerValue: "",
  104. answerNote: {},
  105. selectedSingle: "",
  106. selectedMultiple: [],
  107. recorder: null,
  108. isRecording: false,
  109. indicators: {},
  110. historyStack: [],
  111. nextBtnVisible: true,
  112. webQnUrl: "",
  113. lastCheckList: []
  114. };
  115. },
  116. mounted: function() {
  117. let id = this.getParam("id");
  118. if (!id) {
  119. alert("无效的问卷地址");
  120. return;
  121. }
  122. this.webQnUrl = this.$baseUrl + "/web-qn/" + id;
  123. console.log("webQnUrl", this.webQnUrl);
  124. axios.get(this.webQnUrl + "/judge").then(response => {
  125. console.log("open way:", response.data);
  126. this.openWay = response.data;
  127. if (response.data == "Project") {
  128. console.log("匿名方式问卷打开");
  129. let qnDataUrl = this.webQnUrl + "/complete-info-incognito";
  130. console.log("qnDataUrl:", qnDataUrl);
  131. axios.get(qnDataUrl).then(r => {
  132. this.questionaire = r.data;
  133. this.webQuestionaire = { status: 1 };
  134. // this.webQuestionaire = webQnResponse.data;
  135. // this.questionaire.info = r.data.info;
  136. console.log("匿名方式问卷内容:", this.questionaire);
  137. });
  138. } else {
  139. console.log("登录方式问卷打开");
  140. axios.get(this.webQnUrl).then(webQnResponse => {
  141. let qnId = webQnResponse.data.qnId;
  142. let qnDataUrl = this.webQnUrl + "/complete-info";
  143. console.log("qnDataUrl", qnDataUrl);
  144. axios.get(qnDataUrl).then(r => {
  145. this.questionaire = r.data;
  146. this.webQuestionaire = webQnResponse.data;
  147. // this.questionaire.info = r.data.info;
  148. console.log("登录方式问卷内容", this.questionaire);
  149. });
  150. });
  151. }
  152. // 获取最新的配额
  153. // let $this = this;
  154. // axios.get(`${this.$baseUrl}/questionaire/${this.questionaire.info.id}/indicator`).then(function (response) {
  155. // // $this.indicators = response.data
  156. // for (let i = 0; i < response.data.length; i++) {
  157. // $this.indicators[response.data[i].id] = response.data[i];
  158. // }
  159. // });
  160. // // 将本次运行写入数据库
  161. // if (this.questionaire.info.status >= 3) {
  162. // this.insertAnswerSheet();
  163. // }
  164. // this.onQuestionLoaded();
  165. });
  166. let time = new Date();
  167. this.answerSheet.startTime = dateFormat.formatDate(
  168. "yyyy-MM-dd HH:mm:ss",
  169. time
  170. );
  171. this.answerSheet.sheetName = this.generateSheetName(time);
  172. },
  173. computed: {
  174. stage() {
  175. if (this.webQuestionaire.status == 3) {
  176. // 显示结束语
  177. return 2;
  178. } else if (this.webQuestionaire.status == 2) {
  179. // 显示题目
  180. return 1;
  181. } else {
  182. // 显示问候语
  183. return 0;
  184. }
  185. },
  186. // pageTitle() {
  187. // console.log('compute page title');
  188. // let title = '';
  189. // switch (this.stage) {
  190. // case 0:
  191. // title = "问候语";
  192. // break;
  193. // case 1: title = "问卷内容";
  194. // break;
  195. // case 2: title = "问卷已结束";
  196. // break;
  197. // }
  198. // if (this.isRecording) {
  199. // return `${title}(录音中...)`
  200. // } else {
  201. // return title;
  202. // }
  203. // },
  204. currentQuestion() {
  205. return this.questionaire.questions[this.questionHEAD];
  206. },
  207. percent() {
  208. let perc =
  209. ((this.questionHEAD + 1) / this.questionaire.questions.length) * 100;
  210. console.log("percent", perc);
  211. return perc;
  212. },
  213. questionType() {
  214. let type = this.currentQuestion.type;
  215. if (type == 1) {
  216. if (
  217. this.currentQuestion.minOptions == 1 &&
  218. this.currentQuestion.maxOptions == 1
  219. ) {
  220. return "单选题";
  221. } else {
  222. return "多选题";
  223. }
  224. } else if (type == 3) {
  225. return "排序题";
  226. } else if (type == 4) {
  227. return "开放题";
  228. }
  229. },
  230. questionBody() {
  231. // 处理${ID}的情况
  232. return this.replaceDollarId(this.currentQuestion.body);
  233. },
  234. questionRemark() {
  235. // 处理${ID}的情况
  236. return this.replaceDollarId(this.currentQuestion.remark);
  237. },
  238. upperDatasourceQuestion() {
  239. console.log("call upperDatasourceQuestion");
  240. // 获取上一级的数据源所在的题目id(同一个id,但列数小1的题目)
  241. if (!this.currentQuestion.datasourceId) {
  242. return 0;
  243. } else {
  244. let dsId = this.currentQuestion.datasourceId;
  245. let dsColumn = this.currentQuestion.datasourceColumn;
  246. for (let i = 0; i < this.questionHEAD; i++) {
  247. if (
  248. this.questionaire.questions[i].datasourceId == dsId &&
  249. this.questionaire.questions[i].datasourceColumn == dsColumn - 1
  250. ) {
  251. return this.questionaire.questions[i].id;
  252. }
  253. }
  254. return 0;
  255. }
  256. },
  257. questionOptions() {
  258. console.log("call questionOptions");
  259. let opts = [];
  260. if (this.upperDatasourceQuestion == 0) {
  261. opts = this.currentQuestion.options;
  262. } else {
  263. let dsId = this.currentQuestion.datasourceId;
  264. let dsColumn = this.currentQuestion.datasourceColumn;
  265. let targetOptionId = this.answers[this.upperDatasourceQuestion].answer;
  266. let dsFilter = this.findOptionContent(
  267. this.upperDatasourceQuestion,
  268. targetOptionId
  269. );
  270. let subDataColumn = [];
  271. let datasource = null;
  272. for (let i in this.questionaire.datasource) {
  273. if (this.questionaire.datasource[i].id == dsId) {
  274. datasource = this.questionaire.datasource[i];
  275. break;
  276. }
  277. }
  278. if (!datasource) {
  279. return this.currentQuestion.options;
  280. }
  281. for (let i in datasource.contentList) {
  282. if (datasource.contentList[i]["c" + (dsColumn - 1)] == dsFilter) {
  283. subDataColumn.push(datasource.contentList[i]["c" + dsColumn]);
  284. }
  285. }
  286. let subOptions = [];
  287. for (let i in this.currentQuestion.options) {
  288. if (
  289. this.currentQuestion.options[i].datasourceId == 0 ||
  290. subDataColumn.indexOf(
  291. this.currentQuestion.options[i].optionContent
  292. ) >= 0
  293. ) {
  294. subOptions.push(this.currentQuestion.options[i]);
  295. }
  296. }
  297. opts = subOptions;
  298. }
  299. // 组装成 mt-radio 或 mt-checklist 组件需要的格式
  300. for (let i = 0; i < opts.length; i++) {
  301. // let label = `${i + 1}、${opts[i].optionContent}`;
  302. let label = `${opts[i].optionContent}`;
  303. let value = i.toString();
  304. Vue.set(opts[i], "label", label);
  305. Vue.set(opts[i], "value", value);
  306. }
  307. return opts;
  308. }
  309. },
  310. watch: {
  311. questionHEAD() {
  312. //换题后返回页面顶部
  313. console.log("before scroll", document.documentElement.scrollTop);
  314. document.documentElement.scrollTop = 0;
  315. console.log("after scroll", document.documentElement.scrollTop);
  316. }
  317. },
  318. methods: {
  319. getParam: function(name) {
  320. if (
  321. (name = new RegExp("[?&]" + encodeURIComponent(name) + "=([^&]*)").exec(
  322. location.search
  323. ))
  324. )
  325. return decodeURIComponent(name[1]);
  326. },
  327. // backEventHandler(args) {
  328. // console.log('activityBackPressedEvent......')
  329. // debugger;
  330. // if (this.stage < 2) {
  331. // args.cancel = true;
  332. // this.onQuitTap();
  333. // } else if (this.stage == 2) {
  334. // args.cancel = true;
  335. // this.onFinishTap();
  336. // }
  337. // },
  338. start() {
  339. if (this.openWay == "Project") {
  340. // 匿名方式打开
  341. this.webQuestionaire.status = 2;
  342. } else {
  343. // 登录状态打开方式
  344. this.webQuestionaire.status = 2;
  345. axios
  346. .put(this.webQnUrl, { status: 2 })
  347. .then(() => console.log("update status success"));
  348. }
  349. },
  350. getUserName() {
  351. if (this.openWay == "Project") {
  352. // 匿名方式打开
  353. return "incognito";
  354. } else {
  355. // 登录状态打开方式
  356. return this.webQuestionaire.phoneNumber;
  357. }
  358. },
  359. getOrgCode() {
  360. let orgCode = "webqn";
  361. return orgCode;
  362. },
  363. generateSheetName(time) {
  364. let orgCode = this.getOrgCode();
  365. let userName = this.getUserName();
  366. return `${orgCode}-${dateFormat.formatDate(
  367. "yyyyMMddHHmmss",
  368. time
  369. )}-${userName}`;
  370. },
  371. replaceDollarId(body) {
  372. // 处理${ID}的情况
  373. let regex = /\$\{(\d+)\}/m;
  374. let match = regex.exec(body);
  375. while (match && match[0]) {
  376. let targetQuestionId = match[1];
  377. let targetOptionId = this.answers[targetQuestionId].answer;
  378. let targetOptionContent = this.findOptionContent(
  379. targetQuestionId,
  380. targetOptionId
  381. );
  382. body = body.replace(match[0], targetOptionContent);
  383. match = regex.exec(body);
  384. }
  385. return body;
  386. },
  387. onQuitTap() {
  388. confirm({
  389. title: "请确认",
  390. message: "确定要结束问卷吗?",
  391. okButtonText: "确定",
  392. cancelButtonText: "取消"
  393. }).then(result => {
  394. if (result) {
  395. // 中途拒访
  396. this.finishQuestionaire(2);
  397. }
  398. });
  399. },
  400. onPreTap() {
  401. let lastIndex = this.historyStack.pop();
  402. this.questionHEAD = lastIndex;
  403. this.onQuestionLoaded(true);
  404. },
  405. onListItemTap(event) {
  406. let selectedOpt = event.item;
  407. selectedOpt.isSelected = !selectedOpt.isSelected;
  408. console.log(
  409. "onListItemTap",
  410. `select option: ${selectedOpt.optionContent}, selected? ${selectedOpt.isSelected}`
  411. );
  412. this.onOptionChange(selectedOpt);
  413. },
  414. onOptionSelected(index) {
  415. console.log("option changed : ", typeof index);
  416. let _type = typeof index;
  417. let selectedOpt = null;
  418. if (_type == "object") {
  419. // 多选
  420. let isUnselect = this.lastCheckList.length > index.length;
  421. if (!isUnselect) {
  422. let lastIndex = index[index.length - 1];
  423. selectedOpt = this.questionOptions[lastIndex];
  424. }
  425. // 将本次选项写入this.lastCheckList
  426. this.lastCheckList.length = 0;
  427. for (let i = 0; i < index.length; i++) {
  428. this.lastCheckList.push(index[i]);
  429. }
  430. if (isUnselect) {
  431. return;
  432. }
  433. } else if (_type == "string") {
  434. selectedOpt = this.questionOptions[index];
  435. }
  436. // 处理开放选项
  437. if (selectedOpt.open) {
  438. MessageBox.prompt(selectedOpt.openOptionTips, "请填写").then(
  439. ({ value }) => {
  440. console.log(`Dialog value: ${value}, `);
  441. this.answerNote[selectedOpt.id] = value;
  442. }
  443. );
  444. }
  445. },
  446. onQuestionLoaded(isBack) {
  447. console.log("call onQuestionLoaded");
  448. if (isBack) {
  449. let lastQuestionId = this.questionaire.questions[this.questionHEAD].id;
  450. let lastAnswer = this.answers[lastQuestionId];
  451. this.answerValue = lastAnswer.answer;
  452. if (this.currentQuestion.type == 1 && lastAnswer.answerNote) {
  453. this.answerNote[lastAnswer.answer] = lastAnswer.answerNote;
  454. }
  455. delete this.answers[lastQuestionId];
  456. } else {
  457. this.answerValue = "";
  458. this.answerNote = {};
  459. this.selectedSingle = "";
  460. this.selectedMultiple = [];
  461. }
  462. // 根据题目类型,动态展示对应的答题方式
  463. // ---- 已在页面绑定中体现了
  464. // 处理${ID}的情况
  465. // ---- 已在computed questionBody()中处理
  466. // 处理数据源绑定(如果绑定了数据源并且上一列已经选中,则根据上一列的结果筛选选项)
  467. // ---- 已在computed questionOptions()中处理
  468. // 如果某选项会跳转到结束问卷,则提示出来
  469. // ---- 已在页面绑定中体现了
  470. },
  471. findOptionContent(targetQuestionId, targetOptionId) {
  472. for (let i in this.questionaire.questions) {
  473. if (this.questionaire.questions[i].id == targetQuestionId) {
  474. console.log("target qeustion", this.questionaire.questions[i].body);
  475. for (let j in this.questionaire.questions[i].options) {
  476. if (
  477. this.questionaire.questions[i].options[j].id == targetOptionId
  478. ) {
  479. console.log(
  480. "target option",
  481. this.questionaire.questions[i].options[j].optionContent
  482. );
  483. return this.questionaire.questions[i].options[j].optionContent;
  484. }
  485. }
  486. }
  487. }
  488. },
  489. onQuestionConfirm() {
  490. console.log("onQuestionConfirm...");
  491. // let selections = [];
  492. let selectionIds = [];
  493. let questionId = this.questionaire.questions[this.questionHEAD].id;
  494. if (this.currentQuestion.type == 1) {
  495. if (this.questionType == "单选题") {
  496. if (this.selectedSingle) {
  497. selectionIds.push(this.questionOptions[this.selectedSingle].id);
  498. }
  499. } else {
  500. for (let i = 0; i < this.selectedMultiple.length; i++) {
  501. selectionIds.push(
  502. this.questionOptions[this.selectedMultiple[i]].id
  503. );
  504. }
  505. }
  506. console.log("selectionIds", selectionIds);
  507. if (
  508. this.currentQuestion.maxOptions &&
  509. this.currentQuestion.maxOptions < selectionIds.length
  510. ) {
  511. alert(`最多可选中${this.currentQuestion.maxOptions}项`);
  512. return;
  513. }
  514. if (
  515. this.currentQuestion.minOptions &&
  516. this.currentQuestion.minOptions > selectionIds.length
  517. ) {
  518. alert(`最少需选中${this.currentQuestion.minOptions}项`);
  519. return;
  520. }
  521. // 确定答案
  522. // this.answers[questionId] = selectionIds.join(',');
  523. this.answers[questionId] = {
  524. questionId: questionId,
  525. answer: selectionIds.join(",")
  526. };
  527. if (
  528. this.currentQuestion.maxOptions == 1 &&
  529. this.answerNote[selectionIds[0]]
  530. ) {
  531. this.answers[questionId].answerNote = this.answerNote[
  532. selectionIds[0]
  533. ];
  534. } else if (this.currentQuestion.maxOptions > 1) {
  535. let answerNoteObj = {};
  536. for (let index in selectionIds) {
  537. let selectedId = selectionIds[index];
  538. if (this.answerNote[selectedId]) {
  539. answerNoteObj[selectedId] = this.answerNote[selectedId];
  540. }
  541. }
  542. this.answers[questionId].answerNote = JSON.stringify(answerNoteObj);
  543. }
  544. // 判断是否配额不足
  545. let isIndicartorOut = indicatorBiz.isIndicartorOut(
  546. this.currentQuestion,
  547. this.indicators,
  548. this.answers
  549. );
  550. if (isIndicartorOut) {
  551. // 配额不足,跳转至结束
  552. this.finishQuestionaire(4);
  553. return;
  554. }
  555. // 判断是否需要跳题以及是否需要结束问卷
  556. let hopToQuestionId = 0;
  557. if (
  558. this.currentQuestion.type == 1 &&
  559. this.currentQuestion.maxOptions == 1
  560. ) {
  561. for (let i in this.questionOptions) {
  562. let opt = this.questionOptions[i];
  563. if (opt.id == selectionIds[0] && opt.redirectTo != 0) {
  564. hopToQuestionId = opt.redirectTo;
  565. break;
  566. }
  567. }
  568. }
  569. console.log("hop to question", hopToQuestionId);
  570. if (hopToQuestionId == -2) {
  571. // 甄别不过,跳转至结束
  572. this.finishQuestionaire(3);
  573. return;
  574. } else if (hopToQuestionId == -1) {
  575. // 正常结束
  576. this.finishQuestionaire(1);
  577. return;
  578. } else if (hopToQuestionId > 0) {
  579. // 跳转到某道题
  580. // for (let i in this.questionaire.questions) {
  581. for (let i = 0; i < this.questionaire.questions.length; i++) {
  582. if (this.questionaire.questions[i].id == hopToQuestionId) {
  583. this.questionHEAD = i;
  584. this.onQuestionLoaded();
  585. return;
  586. }
  587. }
  588. }
  589. } else if (this.currentQuestion.type == 3) {
  590. // 排序题
  591. } else if (this.currentQuestion.type == 4) {
  592. // 开放题
  593. if (this.currentQuestion.required && !this.answerValue) {
  594. alert("此项必填");
  595. return;
  596. }
  597. this.answers[questionId] = {
  598. questionId: questionId,
  599. answer: this.answerValue
  600. };
  601. }
  602. if (this.questionHEAD == this.questionaire.questions.length - 1) {
  603. // 所有题目都回答完了,问卷正常结束
  604. this.finishQuestionaire(1);
  605. return;
  606. } else {
  607. // 进入下一道题
  608. this.historyStack.push(this.questionHEAD);
  609. this.questionHEAD++;
  610. }
  611. this.onQuestionLoaded();
  612. },
  613. finishQuestionaire(status) {
  614. if (this.questionaire.info.status >= 3) {
  615. this.answerSheet.status = status;
  616. this.answerSheet.endTime = dateFormat.formatDate(
  617. "yyyy-MM-dd HH:mm:ss",
  618. new Date()
  619. );
  620. let arr = [];
  621. for (let i in this.answers) {
  622. arr.push(this.answers[i]);
  623. }
  624. // 持久化answerSheet数据
  625. // this.updateAnswerSheetData(JSON.stringify(arr));
  626. axios
  627. .post(this.webQnUrl, {
  628. sheet: this.answerSheet,
  629. answers: arr
  630. })
  631. .then(() => {
  632. // this.updateAnswerSheetDataUploaded(true);
  633. // alert('问卷结果已提交');
  634. if (this.openWay == "Project") {
  635. this.webQuestionaire.status = 3;
  636. } else {
  637. // 登录状态打开方式
  638. this.webQuestionaire.status = 3;
  639. }
  640. });
  641. }
  642. },
  643. onFinishTap() {
  644. if (app.android) {
  645. app.android.off(
  646. app.AndroidApplication.activityBackPressedEvent,
  647. this.backEventHandler
  648. );
  649. console.log("backEventHandler off");
  650. }
  651. if (this.isRecord) {
  652. this.recorder.stop().catch(ex => {
  653. console.log("recorder stop failed", ex);
  654. this.isRecording = false;
  655. });
  656. }
  657. this.$modal.close();
  658. },
  659. insertAnswerSheet() {
  660. this.$db.execSQL(
  661. "insert into answer_sheet values(?,?,?,?,?,?,?,?,?,?,?,?)",
  662. [
  663. this.answerSheet.sheetName,
  664. this.answerSheet.questionaireId,
  665. this.answerSheet.status,
  666. this.answerSheet.startTime,
  667. null,
  668. this.answerSheet.locationLong,
  669. this.answerSheet.locationLat,
  670. null,
  671. 0,
  672. this.isRecord ? 1 : 0,
  673. 0,
  674. this.getUserName()
  675. ],
  676. function(err) {
  677. if (err) {
  678. console.error("insertAnswerSheet error", err);
  679. }
  680. }
  681. );
  682. }
  683. // updateAnswerSheetData(answerJson) {
  684. // this.$db.execSQL('update answer_sheet set endTime = ?, answerJson = ?, status = ? where sheetName = ?',
  685. // [
  686. // this.answerSheet.endTime,
  687. // answerJson,
  688. // this.answerSheet.status,
  689. // this.answerSheet.sheetName,
  690. // ], function (err) {
  691. // if (err) {
  692. // console.error('updateAnswerSheetData error', err)
  693. // }
  694. // })
  695. // },
  696. // updateAnswerSheetDataUploaded(isDataUploaded) {
  697. // this.$db.execSQL('update answer_sheet set dataUploaded = ? where sheetName = ?',
  698. // [
  699. // isDataUploaded ? 1 : 0,
  700. // this.answerSheet.sheetName,
  701. // ], function (err) {
  702. // if (err) {
  703. // console.error('updateAnswerSheetDataUploaded error', err)
  704. // }
  705. // })
  706. // }
  707. }
  708. };
  709. </script>
  710. <style scoped>
  711. .button-bottom {
  712. width: 96%;
  713. /* position: absolute; */
  714. /* left: 2%; */
  715. /* bottom: 2%; */
  716. margin-top: 40px;
  717. margin-left: 2%;
  718. }
  719. </style>