testData.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. import HeaderData from "../../components/HeaderData";
  2. import HistogramHorizontal from "../../components/HistogramHorizontal";
  3. import HistogramHorizontals from "../../components/HistogramHorizontals";
  4. import api from '../../api/test'
  5. import editorApi from '../../api/editor'
  6. import timeFormat from '../../util/time'
  7. import { format } from "util";
  8. export default {
  9. components: {
  10. HeaderData, HistogramHorizontal, HistogramHorizontals
  11. },
  12. data() {
  13. return {
  14. isCopy: false,
  15. houseList: [],
  16. ownHouseName: "所属项目",
  17. dataList: [],
  18. isFilter: false,
  19. isShowTable: true,
  20. checkList: [[]],
  21. data: [],
  22. value: [],
  23. oldValue: [],
  24. options: [],
  25. questionList: [],
  26. questionListSel: [],
  27. filterList: [""],
  28. questionChilds: [],
  29. answerData: [],
  30. currentDate: null,
  31. filterStr: "",
  32. chartData: [],
  33. isCrossAnalyse: false,
  34. condition: [],
  35. analyseCommandSel: "全部",
  36. analyseOptions: [],
  37. analyseValue: [],
  38. crossAnalyse: [],
  39. optionsX: [],
  40. optionsXValue: [],
  41. optionsXOldValue: [],
  42. optionsY: [],
  43. optionsYValue: [],
  44. optionsYOldValue: [],
  45. filterXList: [""],
  46. filterYList: [""],
  47. selectedDataList: [],
  48. }
  49. },
  50. watch: {
  51. answerData: function (val) {
  52. var questionList = val.questionList;
  53. this.chartData = []
  54. for (var i = 0; i < questionList.length; i++) {
  55. var question = questionList[i];
  56. var data = []
  57. var optionList = question.optionList;
  58. for (var j = 0; j < optionList.length; j++) {
  59. data.push({ genre: optionList[j].content, sold: optionList[j].answerCount })
  60. }
  61. var conditionQuestion = { data: data, ...question }
  62. this.chartData.push(conditionQuestion);
  63. }
  64. },
  65. analyseCommandSel: function (val) {
  66. this.analyseOptions = [];
  67. this.analyseValue = [];
  68. if (val == "全部") {
  69. } else if (val == "数据包") {
  70. var bagList = this.condition.bagList;
  71. for (var i = 0; i < bagList.length; i++) {
  72. this.analyseOptions.push({ value: bagList[i].analyseBagId, label: bagList[i].title, disabled: false })
  73. }
  74. } else {
  75. var locationList = this.condition.locationList;
  76. let locationTemp = []
  77. for (var i = 0; i < locationList.length; i++) {
  78. var item = locationList[i]
  79. if (item.city == "") {
  80. item.city = item.province;
  81. }
  82. locationTemp.push(item)
  83. }
  84. locationList = locationTemp;
  85. let result = Object.values(locationList.reduce((m, n) => {
  86. if (!m[n.province]) {
  87. m[n.province] = { value: n.province, children: [] }
  88. }
  89. m[n.province].children.push(n)
  90. return m
  91. }, {}))
  92. console.log("XXXX:result:", result)
  93. var arr = []
  94. for (var i = 0; i < result.length; i++) {
  95. var list = result[i].children;
  96. let results = Object.values(list.reduce((m, n) => {
  97. if (!m[n.city]) {
  98. m[n.city] = { value: n.city, label: n.city, children: [] }
  99. }
  100. m[n.city].children.push({ value: n.district, label: n.district })
  101. return m
  102. }, {}))
  103. arr.push({ value: result[i].value, label: result[i].value, children: results })
  104. }
  105. this.analyseOptions = arr;
  106. }
  107. }
  108. },
  109. created() {
  110. this.houseList = [];
  111. editorApi.houseList().then((res) => {
  112. if (res.success) {
  113. this.houseList = res.list;
  114. }
  115. });
  116. this.getTestList();
  117. },
  118. methods: {
  119. async changeTest(item) {
  120. console.log("XXXXXX1", item);
  121. var list = []
  122. for (var i = 0; i < this.dataList.length; i++) {
  123. var element = this.dataList[i]
  124. if (item._id == element._id) {
  125. element.isSelected = !element.isSelected;
  126. }
  127. list.push(element)
  128. }
  129. console.log("XXXxXXX", list);
  130. this.dataList = list;
  131. this.options = []
  132. this.questionList = []
  133. for (var i = 0; i < this.dataList.length; i++) {
  134. var element = this.dataList[i]
  135. if (element.isSelected) {
  136. this.getCNCTestDetail(element)
  137. }
  138. }
  139. this.optionsX = []
  140. for (var i = 0; i < this.dataList.length; i++) {
  141. var element = this.dataList[i]
  142. if (element.isSelected) {
  143. this.getCNCTestDetailX(element)
  144. }
  145. }
  146. this.optionsY = []
  147. for (var i = 0; i < this.dataList.length; i++) {
  148. var element = this.dataList[i]
  149. if (element.isSelected) {
  150. this.getCNCTestDetailY(element)
  151. }
  152. }
  153. },
  154. async getCondition() {
  155. var testThemesIdList = [];
  156. for (var i = 0; i < this.options.length; i++) {
  157. var element = this.options[i]
  158. testThemesIdList.push(element.id);
  159. }
  160. let data = {
  161. testThemesIdList: testThemesIdList
  162. }
  163. api.condition(data).then((res) => {
  164. if (res.success) {
  165. console.log("success", res.single);
  166. this.condition = res.single;
  167. } else {
  168. console.log("error");
  169. }
  170. });
  171. },
  172. async getCNCTestDetail(item) {
  173. this.currentDate = timeFormat.getNowFormatDate();
  174. let data = {
  175. testThemesIdList: [item._id]
  176. }
  177. api.answerData(data).then((res) => {
  178. if (res.success) {
  179. this.answerData = res.single;
  180. console.log("success", res);
  181. var questionList = res.single.questionList;
  182. var children = []
  183. for (var i = 0; i < questionList.length; i++) {
  184. children.push({ value: questionList[i].questionId, label: questionList[i].content, disabled: false })
  185. }
  186. var element = { value: item._id, label: item.title, children: children, id: item._id };
  187. this.options.push(element);
  188. this.questionList = questionList;
  189. // 查询数据包列表
  190. this.getCondition();
  191. } else {
  192. console.log("error");
  193. }
  194. });
  195. },
  196. async getCNCTestDetailX(item) {
  197. let data = {
  198. testThemesIdList: [item._id]
  199. }
  200. api.answerData(data).then((res) => {
  201. if (res.success) {
  202. this.answerData = res.single;
  203. console.log("success", res);
  204. var questionList = res.single.questionList;
  205. var children = []
  206. for (var i = 0; i < questionList.length; i++) {
  207. children.push({ value: questionList[i].questionId, label: questionList[i].content, disabled: false })
  208. }
  209. var element = { value: item._id, label: item.title, children: children, id: item._id };
  210. this.optionsX.push(element);
  211. } else {
  212. console.log("error");
  213. }
  214. });
  215. },
  216. async getCNCTestDetailY(item) {
  217. let data = {
  218. testThemesIdList: [item._id]
  219. }
  220. api.answerData(data).then((res) => {
  221. if (res.success) {
  222. this.answerData = res.single;
  223. console.log("success", res);
  224. var questionList = res.single.questionList;
  225. var children = []
  226. for (var i = 0; i < questionList.length; i++) {
  227. children.push({ value: questionList[i].questionId, label: questionList[i].content, disabled: false })
  228. }
  229. var element = { value: item._id, label: item.title, children: children, id: item._id };
  230. this.optionsY.push(element);
  231. } else {
  232. console.log("error");
  233. }
  234. });
  235. },
  236. handleChange(value, index) {
  237. console.log(value, index, this.oldValue);
  238. for (var i = 0; i < this.questionList.length; i++) {
  239. if (value[1] == this.questionList[i].questionId) {
  240. if (this.oldValue.length >= index + 1) {
  241. console.log("XXXXXXXXXXXXX");
  242. this.setOptionsDisabled(this.oldValue[index], false);
  243. }
  244. this.questionListSel[index] = this.questionList[i];
  245. }
  246. }
  247. this.setOptionsDisabled(value, true);
  248. this.value[index] = value;
  249. this.oldValue[index] = value;
  250. this.checkList.splice(index, 1, []);
  251. this.questionChilds.splice(index, 1, []);
  252. },
  253. handleChangeX(value, index) {
  254. console.log("handleChangeX", value, index, this.optionsXOldValue);
  255. for (var i = 0; i < this.questionList.length; i++) {
  256. if (value[1] == this.questionList[i].questionId) {
  257. if (this.optionsXOldValue.length >= index + 1) {
  258. console.log("XXXXXXXXXXXXX");
  259. this.setOptionsDisabledXY(this.optionsXOldValue[index], false, 0);
  260. this.setOptionsDisabledXY(this.optionsYOldValue[index], false, 1);
  261. }
  262. // this.questionListSel[index] = this.questionList[i];
  263. }
  264. }
  265. this.setOptionsDisabledXY(value, true, 1);
  266. this.setOptionsDisabledXY(value, true, 0);
  267. this.optionsXValue[index] = value;
  268. this.optionsXOldValue[index] = value;
  269. // this.checkList.splice(index, 1, []);
  270. // this.questionChilds.splice(index, 1, []);
  271. },
  272. handleChangeY(value, index) {
  273. console.log("handleChangeX", value, index, this.optionsYOldValue);
  274. for (var i = 0; i < this.questionList.length; i++) {
  275. if (value[1] == this.questionList[i].questionId) {
  276. if (this.optionsYOldValue.length >= index + 1) {
  277. console.log("XXXXXXXXXXXXX");
  278. this.setOptionsDisabledXY(this.optionsYOldValue[index], false, 1);
  279. this.setOptionsDisabledXY(this.optionsYOldValue[index], false, 0);
  280. }
  281. // this.questionListSel[index] = this.questionList[i];
  282. }
  283. }
  284. this.setOptionsDisabledXY(value, true, 1);
  285. this.setOptionsDisabledXY(value, true, 0);
  286. this.optionsYValue[index] = value;
  287. this.optionsYOldValue[index] = value;
  288. // this.checkList.splice(index, 1, []);
  289. // this.questionChilds.splice(index, 1, []);
  290. },
  291. addfilterX() {
  292. this.filterXList.push('');
  293. },
  294. addfilterY() {
  295. this.filterYList.push('');
  296. },
  297. handleAnalyseChange(value) {
  298. console.log(value);
  299. },
  300. setOptionsDisabledXY(value, disabled, type = 0) {
  301. var newOptions = [];
  302. console.log("XXXXXXX", value)
  303. var options = type == 0 ? this.optionsX : this.optionsY;
  304. for (var i = 0; i < options.length; i++) {
  305. var item = options[i];
  306. if (item.value == value[0]) {
  307. for (var j = 0; j < options[i].children.length; j++) {
  308. var children = []
  309. var element = options[i].children[j];
  310. if (element.value == value[1]) {
  311. element.disabled = disabled
  312. }
  313. children.push(element)
  314. }
  315. }
  316. newOptions.push(item)
  317. }
  318. if (type == 0) {
  319. this.optionsX = newOptions;
  320. } else {
  321. this.optionsY = newOptions;
  322. }
  323. },
  324. setOptionsDisabled(value, disabled) {
  325. var newOptions = [];
  326. console.log("XXXXXXX", value)
  327. for (var i = 0; i < this.options.length; i++) {
  328. var item = this.options[i];
  329. if (item.value == value[0]) {
  330. for (var j = 0; j < this.options[i].children.length; j++) {
  331. var children = []
  332. var element = this.options[i].children[j];
  333. if (element.value == value[1]) {
  334. element.disabled = disabled
  335. }
  336. children.push(element)
  337. }
  338. }
  339. newOptions.push(item)
  340. }
  341. this.options = newOptions;
  342. },
  343. addFilter() {
  344. this.filterList.push('');
  345. this.checkList.push([]);
  346. },
  347. delFilter(index) {
  348. if (this.value[index]) {
  349. this.setOptionsDisabled(this.value[index], false);
  350. }
  351. this.filterList.splice(index, 1);
  352. this.value.splice(index, 1);
  353. this.questionListSel.splice(index, 1);
  354. this.questionChilds.splice(index, 1);
  355. this.checkList.splice(index, 1);
  356. },
  357. projectCommand(command) {
  358. if (this.houseList.indexOf(command) == -1) {
  359. console.log("不存在");
  360. this.ownHouseName = "所属项目";
  361. } else {
  362. console.log("存在", command.houseName);
  363. this.ownHouseName = command.houseName;
  364. }
  365. this.getTestList();
  366. },
  367. analyseCommand(command) {
  368. console.log("XXXXXXX", command)
  369. if (command == -1) {
  370. this.analyseCommandSel = "全部";
  371. } else if (command == 0) {
  372. this.analyseCommandSel = "数据包";
  373. } else {
  374. this.analyseCommandSel = "区域";
  375. }
  376. // this.getTestList();
  377. },
  378. changequestionChild(checked, value, index) {
  379. console.log("XXXXXX", value, index, checked);
  380. var arr = this.questionChilds;
  381. if (this.questionChilds.length <= index) { // 没有
  382. if (checked) {
  383. console.log("选中");
  384. for (var i = 0; i < this.filterList.length; i++) {
  385. if (i < index) {
  386. if (this.questionChilds.length < index) {
  387. this.questionChilds.push([]);
  388. }
  389. }
  390. }
  391. this.questionChilds.push([value]);
  392. } else {
  393. console.log("取消选中")
  394. }
  395. } else { // 有
  396. console.log("有")
  397. var questionList = this.questionChilds[index];
  398. if (checked) {
  399. questionList.push(value)
  400. } else {
  401. var arr = questionList;
  402. for (var i = 0; i < questionList.length; i++) {
  403. var option = questionList[i];
  404. if (option.optionId == value.optionId) {
  405. arr.splice(i, 1);
  406. }
  407. }
  408. questionList = arr;
  409. }
  410. this.questionChilds[index] = questionList;
  411. }
  412. },
  413. getTestList() {
  414. let data = {
  415. "orderType": "",
  416. "ownHouseName": this.ownHouseName == "所属项目" ? '' : this.ownHouseName,
  417. "pageNo": 1,
  418. "pageSize": 100,
  419. "houseAnswerStatus": ""
  420. }
  421. api.testList(data).then((res) => {
  422. if (res.success) {
  423. this.total = res.pageModel.total;
  424. this.dataList = [];
  425. this.dataList.push(...res.pageModel.resultSet);
  426. this.dataList.forEach(element => {
  427. element.isSelected = false
  428. });
  429. console.log("success", this.dataList, res.pageModel);
  430. } else {
  431. console.log("error");
  432. }
  433. });
  434. },
  435. async getAnswerData() {
  436. this.filterStr = "";
  437. var conditionQuestionList = [];
  438. var testThemesIdList = [];
  439. for (var i = 0; i < this.questionChilds.length; i++) {
  440. var question = this.questionChilds[i];
  441. var value = this.value[i];
  442. var optionList = [];
  443. for (var j = 0; j < question.length; j++) {
  444. optionList.push({ optionId: question[j].optionId })
  445. this.filterStr += question[j].content + "/";
  446. }
  447. var conditionQuestion = { questionId: value[1], optionList: optionList }
  448. conditionQuestionList.push(conditionQuestion);
  449. }
  450. for (var i = 0; i < this.options.length; i++) {
  451. testThemesIdList.push(this.options[i].id);
  452. }
  453. this.filterStr = this.filterStr.substr(0, this.filterStr.length - 1)
  454. let data = {
  455. conditionQuestionList: conditionQuestionList,
  456. testThemesIdList: testThemesIdList
  457. }
  458. api.answerData(data).then((res) => {
  459. if (res.success) {
  460. this.answerData = res.single;
  461. console.log("success", res);
  462. } else {
  463. console.log("error");
  464. }
  465. });
  466. },
  467. saveOnLine() {
  468. var checkList = [];
  469. for (var i = 0; i < this.questionChilds.length; i++) {
  470. var question = this.questionChilds[i]
  471. for (var j = 0; j < question.length; j++) {
  472. var option = question[j];
  473. var questionObj = this.questionListSel[i];
  474. console.log("SSSSSS", option, questionObj);
  475. checkList.push({ subOptionContent: option.content, subOptionId: option.optionId, subQuestionContent: questionObj.content, subQuestionId: questionObj.questionId })
  476. }
  477. }
  478. console.log("编辑数据包", checkList);
  479. this.$prompt("请数据包名称", "提保存筛选条件作为数据包", {
  480. confirmButtonText: "确定",
  481. cancelButtonText: "取消",
  482. inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
  483. inputErrorMessage: "数据包名称不为空",
  484. inputValue: this.title
  485. })
  486. .then(({ value }) => {
  487. let param = {
  488. checkList: checkList,
  489. analyseBagTitle: value,
  490. operator: "admin"
  491. };
  492. api.saveAnalyseBag(param).then(res => {
  493. if (res.success) {
  494. this.$message.success("保存成功");
  495. } else {
  496. this.$message.error("数据加载失败,请重试");
  497. }
  498. });
  499. })
  500. .catch(() => { });
  501. },
  502. async getCrossAnalyse() {
  503. var testThemesIdList = [];
  504. for (var i = 0; i < this.options.length; i++) {
  505. testThemesIdList.push(this.options[i].id);
  506. }
  507. var xlist = [];
  508. var ylist = [];
  509. for (var i = 0; i < this.questionList.length; i++) {
  510. var item = this.questionList[i];
  511. for (var m = 0; m < this.optionsXValue.length; m++) {
  512. var element = this.optionsXValue[m];
  513. if (item.questionId == element[1]) {
  514. xlist.push(item);
  515. }
  516. }
  517. for (var n = 0; n < this.optionsYValue.length; n++) {
  518. var element = this.optionsYValue[n];
  519. if (item.questionId == element[1]) {
  520. ylist.push(item);
  521. }
  522. }
  523. }
  524. let data = {
  525. testThemesIdList: testThemesIdList,
  526. xlist: xlist,
  527. ylist: ylist
  528. }
  529. console.log("XXXXXX", data);
  530. api.crossAnalyse(data).then((res) => {
  531. if (res.success) {
  532. console.log("success", res.list);
  533. var crossAnalyse = res.list;
  534. this.crossAnalyse = []
  535. var result = [];
  536. var rowArr = [];
  537. for (var n = 0; n < crossAnalyse.length; n++) {
  538. var arrs = []
  539. var crossResult = crossAnalyse[n].crossResult;
  540. console.log("XXXXX", Object.keys(crossResult), Object.values(crossResult))
  541. rowArr = Object.keys(crossResult);
  542. var values = Object.values(crossResult)
  543. for (var m = 0; m < values.length; m++) {
  544. console.log("SSSSS", Object.keys(values[m]), Object.values(values[m]))
  545. arrs.push({ name: Object.keys(values[m]), value: Object.values(values[m]) })
  546. }
  547. result.push(arrs);
  548. }
  549. console.log("AAAAAA", result);
  550. for (var x = 0; x < result.length; x++) {
  551. var qqq = result[x];
  552. var sss = [];
  553. for (var q = 0; q < qqq.length; q++) {
  554. sss.push({ name: rowArr[q], title: qqq[q].name, value: qqq[q].value })
  555. }
  556. this.crossAnalyse.push(sss);
  557. }
  558. console.log("SSSSS", this.crossAnalyse);
  559. var data = [];
  560. for (var x = 0; x < this.crossAnalyse.length; x++) {
  561. var top = this.crossAnalyse[x];
  562. for (var y = 0; y < top.length; y++) {
  563. var one = top[y].value;
  564. console.log("one", top[y].name)
  565. for (var z = 0; z < one.length; z++) {
  566. var two = one[z];
  567. data.push({ time: top[y].name, type: top[y].title[z], value: two })
  568. }
  569. }
  570. }
  571. console.log("data", data);
  572. this.data = data
  573. } else {
  574. console.log("error");
  575. }
  576. });
  577. }
  578. },
  579. }