webgl_rxdz_test1_env.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template src="./webgl_rxdz_test1_env.html">
  2. </template>
  3. <script>
  4. const util = require('@/utils/util.js').default;
  5. const config = require('@/services/urlConfig.js');
  6. import router from "@/router";
  7. import {
  8. setStorage,
  9. getStorage,
  10. removeItem,
  11. } from '@/utils/localStorage';
  12. import {
  13. Toast
  14. } from 'mint-ui';
  15. import { MessageBox } from 'mint-ui';
  16. import touchHandle from '@/mixins/touchHandle.js';
  17. import createImgHandle from '@/mixins/createImgHandle.js';
  18. import commonPageMethod from '@/mixins/commonPageMethod.js';
  19. export default {
  20. mixins: [touchHandle, commonPageMethod,createImgHandle],
  21. /**
  22. * 页面的初始数据
  23. */
  24. data() {
  25. return {
  26. pvId: 'p_2cmina_21012501',
  27. locusBehaviorName: "环境偏好",
  28. locusValue: "",
  29. locusName: "",
  30. pvCurPageName: "role_set",
  31. pvCurPageParams: null,
  32. navbar: {
  33. showCapsule: 1,
  34. title: '环境偏好',
  35. titleColor: '#fff',
  36. navPadding: 0,
  37. navPaddingBg: 'transparent',
  38. navBarColor: 'transparent',
  39. navBackColor: 'transparent',
  40. haveCallback: false, // 如果是 true 会接手 navbarBackClk
  41. fromShare: false,
  42. fromProject: 0,
  43. shareToken: "",
  44. pageName: this.pvCurPageName,
  45. },
  46. houseId: $config.houseIdHs,
  47. id: '', //题目
  48. allSelect:false,//是否所有大类都选择了
  49. currentIndex: 0,
  50. // featureImgList: [],
  51. showPhoneModel: false,
  52. tabIndex: 0, //当前在第几个tab
  53. optionIndex: -1, //选项选中的序号
  54. options: [], //选项数据
  55. aiImagesList: [], //角色数据,单独
  56. AIImg:'', //AI生成所需要的垫图
  57. tabData: [],
  58. checked:false, //是否喜欢
  59. subDataList:[], //提交的数据对象
  60. queryObj:null,
  61. }
  62. },
  63. /**
  64. * 生命周期函数--监听页面加载
  65. */
  66. mounted(options) {
  67. console.log("***onLoad-webgl_rxdz_customize***", this.$route.query)
  68. const that = this;
  69. this.houseId = this.$route.query.houseId ? this.$route.query.houseId : (this.$store.state.houseId || '');
  70. let queryObj = getStorage('queryObj') ? JSON.parse(getStorage('queryObj')) : null;
  71. this.id = this.$route.query.id3 ? this.$route.query.id3 : (queryObj && queryObj.id3?queryObj.id3:'111');
  72. this.queryObj = queryObj;
  73. this.queryTestcaseSingle();
  74. },
  75. computed: {
  76. userId() {
  77. return this.$store.state.userId;
  78. },
  79. },
  80. methods: {
  81. swiperChangeImg(e) {
  82. console.log("***swiperChangeImg***", e);
  83. this.currentIndex = e.detail ? e.detail.current : e;
  84. this.checked = this.aiImagesList[this.currentIndex].checked;
  85. // this.optionIndex = this.currentIndex;
  86. // this.tabData[0].checkedIndex = this.currentIndex;
  87. },
  88. rightScroll() { //右滑
  89. if (this.currentIndex <= (this.aiImagesList.length - 1) && this.currentIndex > 0) {
  90. this.$refs.carousel.prev();
  91. this.$forceUpdate()
  92. }
  93. },
  94. leftScroll() { //继续生成
  95. console.log("***leftScroll***", this.currentIndex,this.aiImagesList.length);
  96. if (this.currentIndex != this.aiImagesList.length - 1) {
  97. if (this.currentIndex < this.aiImagesList.length - 1) {
  98. this.$refs.carousel.next();
  99. }
  100. return false;
  101. }
  102. console.log("***leftScroll***",this.AIImg,this.options)
  103. let obj = {
  104. imgUrl:this.AIImg,
  105. prompt:this.options[this.optionIndex].remark,
  106. negativePrompt:this.options[this.optionIndex].tips,
  107. tabIndex:this.tabIndex,
  108. optionIndex:this.optionIndex,
  109. }
  110. this.startServer(obj);//继续生成下一张
  111. },
  112. //点赞喜欢
  113. changeAIImg() {
  114. // let lastPage = getCurrentPages()[getCurrentPages().length - 2] ? getCurrentPages()[getCurrentPages().length - 2].$vm : null;
  115. this.checked = !this.checked;//变更选项
  116. this.aiImagesList[this.currentIndex].checked = this.checked;
  117. console.warn("***changeAIImg***",this.checked)
  118. let img = this.aiImagesList[this.currentIndex].imageUrl;
  119. let obj = this.options[this.optionIndex].hardboundEffect.find(it=>it.imageUrl==img);
  120. if(obj){
  121. obj.checked = this.checked;
  122. }
  123. },
  124. //查询题目数据
  125. async queryTestcaseSingle() {
  126. let userId = this.userId || '';
  127. let params = {
  128. id: this.id,
  129. brandId: $config.brandId,
  130. houseId: this.houseId,
  131. userId,
  132. };
  133. // params.userId = this.userId;
  134. const res = await requestConfig('queryTestcaseSingle', params);
  135. if (res.success) {
  136. let list = res.list;
  137. list.forEach(it => {
  138. it.checkedIndex = -1;////增加当前题目用户选择的需要,默认不选中
  139. it.options.forEach(option=>{
  140. if(option.imageUrls){
  141. option.hardboundEffect = option.imageUrls.map(it=>{
  142. return {
  143. imageUrl: it,
  144. checked: false,
  145. type:'system',//表示系统生成的
  146. }
  147. })
  148. }
  149. // option.hardboundEffect = [
  150. // {
  151. // imageUrl :option.imageUrl,
  152. // type:'system',//人为添加的
  153. // }
  154. // ];//AI生成图存放对象
  155. })
  156. });
  157. let envData = getStorage('envData') ? JSON.parse(getStorage('envData')) : null;
  158. this.tabData = list;
  159. this.tabData[0].checkedIndex = 0;
  160. this.optionIndex = 0;
  161. this.options = this.tabData[0].options; //选项数据
  162. this.AIImg = this.tabData[0].options[0].imageUrl;//AI生成所需的垫图
  163. this.aiImagesList = this.tabData[0].options[0].hardboundEffect;
  164. if(envData && envData.length>0){
  165. removeItem('envData');//用完后删除
  166. }else{
  167. this.submitAnswer()
  168. }
  169. //初始化待提交的数据对象
  170. // list.forEach(it=>{
  171. // let obj = {
  172. // fatherContent:it.fatherContent,
  173. // name:it.fatherContent,
  174. // houseId:it.houseId,
  175. // houseName:it.houseName,
  176. // id:it.id,
  177. // hardboundEffect:[]
  178. // }
  179. // this.subDataList.push(obj);
  180. // });
  181. }
  182. },
  183. //切换大类
  184. changeTab(id) {
  185. if (id == this.tabIndex) {
  186. return
  187. }
  188. this.tabIndex = id;
  189. this.options = this.tabData[this.tabIndex].options; //选项数据
  190. this.optionIndex = this.tabData[this.tabIndex].checkedIndex; //获取用户已经选中的选项
  191. if(this.optionIndex>-1){
  192. this.aiImagesList = this.options[this.optionIndex].hardboundEffect;
  193. this.checked = this.aiImagesList[this.currentIndex].checked;
  194. }
  195. // let param = {
  196. // type: 'CLK', //埋点类型
  197. // clkId: 'clk_2cmina_24012601', //点击ID
  198. // clkName: 'tab_clk', //点击前往的页面名称
  199. // clkParams: {
  200. // type: this.tabData[this.tabIndex].fatherContent,
  201. // locusName: "大类选择",
  202. // }
  203. // };
  204. // util.trackRequest(param);
  205. },
  206. //切换选项
  207. changeOption(id) {
  208. if (id == this.optionIndex) {
  209. return false;
  210. }
  211. this.optionIndex = id;
  212. this.tabData[this.tabIndex].checkedIndex = this.optionIndex;
  213. this.allSelect = !this.tabData.some(it=>it.checkedIndex==-1);
  214. this.AIImg = this.options[this.optionIndex].imageUrl;//AI生成图的垫图
  215. //替换对应的队列为选中的选项的数组对象
  216. this.aiImagesList = this.options[this.optionIndex].hardboundEffect;
  217. this.currentIndex = 0;
  218. this.$refs.carousel.setActiveItem(0); //切换到第一张
  219. this.checked = this.aiImagesList[this.currentIndex].checked;
  220. console.warn("***changeOption***", this.tabData,this.AIImg,this.subDataList)
  221. // let param = {
  222. // type: 'CLK', //埋点类型
  223. // clkId: 'clk_2cmina_24012602', //点击ID
  224. // clkName: 'option_clk', //点击前往的页面名称
  225. // clkParams: {
  226. // type: this.options[this.optionIndex].content,
  227. // locusName: "选项选择",
  228. // }
  229. // };
  230. // util.trackRequest(param);
  231. this.submitAnswer()
  232. },
  233. submitAnswer(){
  234. let userId = this.userId || '';
  235. let params = {
  236. "answerContent": [
  237. {
  238. "optionTitle": this.options[this.optionIndex].content,
  239. "questionTitle": this.tabData[this.tabIndex].subContent,//问题标题
  240. "subOptionId": this.options[this.optionIndex].id,
  241. "subQuestionId": this.tabData[this.tabIndex].id,
  242. }
  243. ],
  244. brandId: $config.brandId,
  245. houseId: this.houseId,
  246. channel:this.queryObj ? this.queryObj.channel : '',
  247. city:this.queryObj ? this.queryObj.city : '',
  248. district:this.queryObj ? this.queryObj.district : '',
  249. province:this.queryObj ? this.queryObj.province : '',
  250. paperTitle:'',//试卷id
  251. testThemeId:'',
  252. testcaseId:this.id,
  253. uuid:userId,
  254. xcxCustomerId:userId,
  255. };
  256. requestConfig('submitAnswer', params,true);
  257. let param = {
  258. type: 'CLK', //埋点类型
  259. clkId: 'clk_2cmina_24022003', //点击ID
  260. clkName: 'option_clk', //点击前往的页面名称
  261. clkParams: {
  262. locusValue: this.options[this.optionIndex].content,
  263. locusName: "选项选择",
  264. }
  265. };
  266. util.trackRequest(param);
  267. },
  268. catchTouchMove: function() {
  269. return false;
  270. },
  271. //提交结果数据处理
  272. async resultDataHandle(){
  273. let otherlist = [];
  274. this.tabData.forEach(tab=>{
  275. let list = tab.options[tab.checkedIndex].hardboundEffect.filter(it=>it.checked==true);//过滤选中的
  276. list = list.map(it=>{
  277. return it.imageUrl
  278. })
  279. let obj = tab.options[tab.checkedIndex];
  280. let data = {
  281. spaceName:tab.fatherName,
  282. spaceId:'',
  283. hardboundEffect:(list && list.length>0)?list:[obj.imageUrl],
  284. }
  285. otherlist.push(data);
  286. })
  287. setStorage('thirdData', otherlist);//把环境选择的数据存入本地缓存里面,方便后续使用
  288. let firstData = JSON.parse(getStorage('firstData'));
  289. let secondData = JSON.parse(getStorage('secondData'));
  290. let thirdData = JSON.parse(getStorage('thirdData'));
  291. let curHouseObj = JSON.parse(getStorage('curHouseObj'));
  292. let spaceList = JSON.parse(getStorage('spaceList'));
  293. let shottingImg = getStorage('shottingImg');
  294. let expand = [];//扩展数据
  295. let checkIndexList = [];
  296. let userId = this.userId ? this.userId : '';
  297. let houseData = {
  298. "layoutId": curHouseObj.id,
  299. "layoutName": curHouseObj.name,
  300. "layoutArea": curHouseObj.houseArea,
  301. "floor": 1,
  302. "layoutImgCustomized": shottingImg,
  303. "style": "",
  304. "houseJson": []
  305. }
  306. firstData.forEach(it=>{
  307. let _dt = {
  308. name:it.name,
  309. value:it.selectOptionImageUrl,
  310. }
  311. expand.push(_dt);
  312. })
  313. secondData.forEach(it=>{
  314. let _dt = {
  315. name:it.name,
  316. value:it.selectOptionName,
  317. }
  318. expand.push(_dt);
  319. })
  320. thirdData.forEach(it=>{
  321. let _dt = {
  322. name:it.fatherName,
  323. value:it.options[it.checkedIndex].content,
  324. }
  325. expand.push(_dt);
  326. checkIndexList.push(it.checkedIndex);
  327. })
  328. // this.tabData.forEach(tab=>{
  329. // let list = tab.options[tab.checkedIndex].hardboundEffect.filter(it=>it.checked==true);//过滤选中的
  330. // list = list.map(it=>{
  331. // return it.imageUrl
  332. // })
  333. // let obj = tab.options[tab.checkedIndex];
  334. // let data = {
  335. // spaceName:tab.fatherName,
  336. // spaceId:'',
  337. // hardboundEffect:(list && list.length>0)?list:[obj.imageUrl],
  338. // }
  339. // otherlist.push(data);
  340. // expand.push({
  341. // name:tab.fatherName,
  342. // value:obj.content,
  343. // });
  344. // checkIndexList.push(tab.checkedIndex);
  345. // })
  346. houseData.houseJson = spaceList.concat(otherlist);
  347. // houseData.expand = expand;
  348. let param = {
  349. "brandId": $config.brandId,
  350. "houseId": this.houseId || curHouseObj.houseId,
  351. "userId": userId,
  352. "floot": 1,
  353. "spaceName": curHouseObj.name,
  354. "spaceStructure": '',
  355. "curFloor":1,
  356. layoutStruct:[houseData],
  357. type:'QIANCE',
  358. expand:JSON.stringify(expand),
  359. }
  360. console.warn("submitHouse-param: ", param);
  361. setStorage('envData',checkIndexList);
  362. const loading = this.$loading({
  363. lock: true,
  364. text: '提交中...',
  365. spinner: 'el-icon-loading',
  366. background: 'rgba(0, 0, 0, 0.7)'
  367. });
  368. let res = await requestConfig("saveCustomizedRecord", param);
  369. loading.close();
  370. if(res && res.success && res.single){//提交成功
  371. let data = {
  372. houseId:this.houseId || curHouseObj.houseId,
  373. id:res.single,
  374. }
  375. router.push({
  376. name: "webgl_rxdz_text_customize",
  377. query:data
  378. });
  379. }
  380. },
  381. //进入下一步
  382. enterAction() {
  383. let index = this.tabData.findIndex(it=>it.checkedIndex==-1);
  384. if(index>-1){
  385. Toast({
  386. message: this.tabData[index].fatherContent + '选项不能为空',
  387. });
  388. return false;
  389. }
  390. let otherlist = [];
  391. this.tabData.forEach(tab=>{
  392. let list = tab.options[tab.checkedIndex].hardboundEffect.filter(it=>it.checked==true);//过滤选中的
  393. list = list.map(it=>{
  394. return it.imageUrl
  395. })
  396. let obj = tab.options[tab.checkedIndex];
  397. let data = {
  398. spaceName:tab.fatherName,
  399. spaceId:'',
  400. selectOptionName:obj.content,
  401. hardboundEffect:(list && list.length>0)?list:[obj.imageUrl],
  402. }
  403. otherlist.push(data);
  404. })
  405. setStorage('thirdData', otherlist);//把环境选择的数据存入本地缓存里面,方便后续使用
  406. let data = {
  407. houseId:this.houseId || 100297,
  408. }
  409. router.push({
  410. name: "webgl_rxdz_test_houseList",
  411. query:data
  412. });
  413. },
  414. }
  415. }
  416. </script>
  417. <style lang="scss" scoped>
  418. @import "./webgl_rxdz_test1_env.scss";
  419. </style>