webgl_rxdz_env.vue 12 KB

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