templateStyle.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <div class="mainBox">
  3. <div class="layerBox">
  4. <tableTitle :name="templateStepTitle" />
  5. <step :activeNumber="2" />
  6. </div>
  7. <!--搜索功能 start------------------------------------------------------------>
  8. <div class="layerBox_search">
  9. <div class="layerBoxLine">
  10. <el-row>
  11. <el-col :span="8">
  12. <div class="searchBox">
  13. <div class="searchTitle">按风格搜索</div>
  14. <el-select v-model="getApiData.template_class_id" placeholder="请选择..">
  15. <el-option v-for="item in allClass" :key="item.value" :label="item.label"
  16. :value="item.value">
  17. </el-option>
  18. </el-select>
  19. </div>
  20. </el-col>
  21. <el-col :span="8">
  22. <div class="searchBox">
  23. <div class="searchTitle">按关键字搜索</div>
  24. <el-input v-model="getApiData.keyword[0]" placeholder="根据描述推荐皮肤"></el-input>
  25. </div>
  26. </el-col>
  27. <el-col :span="8">
  28. <div class="searchBtnBox">
  29. <el-button type="primary" @click="getData('search')">搜索</el-button>
  30. </div>
  31. </el-col>
  32. </el-row>
  33. </div>
  34. </div>
  35. <!--搜索功能 end------------------------------------------------------------>
  36. <!--表格内容 start------------------------------------------------------------>
  37. <div class="layerBox">
  38. <tableTitle :name="tableDivTitle" />
  39. <div class="templateStyleBox">
  40. <div class="templateStyleItem" v-for="(item, index) in tableData" :key="index">
  41. <div :class="['templateStyleItemBox', { active: item.status == 1 || item.id == userTemplateId }]" @click="useIt(item)">
  42. <img :src="item.template_img[0].url">
  43. <div class="templateStyleItemTitle">{{ item.template_name }}</div>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="paginationBox">
  48. <el-pagination
  49. @size-change="handleSizeChange"
  50. :current-page="getApiData.page"
  51. @current-change="handleCurrentChange"
  52. :page-size="10"
  53. layout="total, prev, pager, next, jumper"
  54. :total="allCount"
  55. >
  56. </el-pagination>
  57. </div>
  58. </div>
  59. <div class="layerBox">
  60. <tableTitle :name="useTemplateName" />
  61. <div class="thumbnailBox">
  62. <div class="thumbnailItem" @click="showImg(item.url)" v-for="item in userData">
  63. <div class="thumbnailItemBox">
  64. <img :src="item.url">
  65. <div class="thumbnailItemTitle">{{ item.name }}</div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <!--步骤按钮 start------------------------------------------------------------>
  71. <div class="btnBox">
  72. <el-button type="info" @click="goBase">上一步</el-button>
  73. <el-button type="primary" @click="addData">下一步</el-button>
  74. </div>
  75. <!--步骤按钮 end------------------------------------------------------------>
  76. <!--表格内容 end------------------------------------------------------------>
  77. <!--弹出框 start------------------------------------------------------------>
  78. <el-dialog title="模板详情" :visible.sync="windowStatus" :close-on-click-modal="false">
  79. <div class="imgZoomBox">
  80. <img :src="classPic">
  81. </div>
  82. <div slot="footer" class="dialog-footer">
  83. <div class="alignCenterBox">
  84. <el-button @click="windowStatus = false">关闭</el-button>
  85. </div>
  86. </div>
  87. </el-dialog>
  88. <!--弹出框 end------------------------------------------------------------>
  89. </div>
  90. </template>
  91. <script>
  92. //表格标题
  93. import tableTitle from './public/tableTitle';
  94. //引入公用样式
  95. import '@/styles/global.less';
  96. //步骤条
  97. import step from './public/step';
  98. export default {
  99. components: {
  100. tableTitle,//表格标题
  101. step//步骤条
  102. },
  103. data() {
  104. return {
  105. //1.列表和分页相关 start ------------------------------------------------------------>
  106. templateStepTitle: "仅需四步,即可完成模板创建",
  107. tableDivTitle: "模板列表",
  108. useTemplateName: "已选择风格",
  109. allClass: [],//所有风格
  110. windowStatus: false,//弹出框
  111. classPic: "",//放大缩略图
  112. tableData: [],//内容
  113. getApiData: {//搜索功能
  114. website_id: "",
  115. template_class_id: "",
  116. keyword: [],
  117. page: 1,
  118. page_size: 10
  119. },
  120. //用户选择的页面模板
  121. userData: [],
  122. userTemplateId: "",//用户选择的模板风格id
  123. allCount: 0,//总条数
  124. //分页相关 end ------------------------------------------------------------>
  125. }
  126. },
  127. methods: {
  128. //0.全局操作 start ------------------------------------------------------------>
  129. //上一步
  130. goBase() {
  131. this.$router.push({
  132. path: '/templateBase',
  133. query: {
  134. website_id: this.$route.query.website_id
  135. }
  136. });
  137. },
  138. //放大缩略图
  139. showImg(img) {
  140. this.windowStatus = true;
  141. this.classPic = img;
  142. },
  143. //0.全局操作 end ------------------------------------------------------------>
  144. //1.风格列表 start ------------------------------------------------------------>
  145. //1.1 获得所有风格
  146. getAllClass(type) {
  147. this.$store.dispatch('template/getAllTemplateClass', this.getApiData).then(res => {
  148. if (res.code != 200) {
  149. this.$message.error(res.message)
  150. } else {
  151. for (let item of res.data) {
  152. let data = {};
  153. data.value = item.id
  154. data.label = item.name
  155. this.allClass.push(data)
  156. }
  157. }
  158. })
  159. },
  160. //1.2 获得所有模板
  161. getData(type) {
  162. this.$store.dispatch('template/getWebsiteTemplateList', this.getApiData).then(res => {
  163. if(res.code == 200){
  164. console.log(res.data)
  165. let data = res.data.template.data;
  166. //格式化data中的template_img
  167. for(let item of data){
  168. item.template_img = JSON.parse(item.template_img);
  169. console.log(item.template_img[0].url)
  170. item.status = 0;
  171. }
  172. console.log(data)
  173. //展示数据
  174. this.tableData = data;
  175. //总条数
  176. this.allCount = res.data.template.total;
  177. //标记用户之前的选择
  178. if(res.data.template_id==0||res.data.template_id==null){
  179. console.log("用户从未选择过皮肤!")
  180. }else{
  181. this.userTemplateId = res.data.template_id;
  182. for(let item of this.tableData){
  183. if(item.id == this.userTemplateId){
  184. item.status = 1;
  185. this.userData = item.template_img;
  186. this.userTemplateId = item.id;
  187. }
  188. }
  189. }
  190. }else{
  191. this.$message.error(res.message)
  192. }
  193. })
  194. },
  195. //1.3 选中一个模板
  196. useIt(item) {
  197. for (let item of this.tableData) {
  198. item.status = 0;
  199. }
  200. item.status = 1;
  201. this.userData = item.template_img;
  202. this.userTemplateId = item.id;
  203. },
  204. //1.4 列表内容分页
  205. //直接跳转
  206. handleSizeChange(val) {
  207. this.getApiData.page = val;
  208. this.getData();
  209. },
  210. //1.5 点击分页
  211. handleCurrentChange(val) {
  212. this.getApiData.page = val;
  213. this.getData();
  214. },
  215. //1.风格列表 end ------------------------------------------------------------>
  216. //2.提交风格模板 start ------------------------------------------------------------>
  217. addData() {
  218. //2.1 判断是否已经选择了模板
  219. console.log(this.userData.length)
  220. if (this.userData.length == 0) {
  221. console.log("未选择模板")
  222. this.$message.error("必须选择一个模板风格!")
  223. } else {
  224. let data = {
  225. website_id: this.$route.query.website_id,
  226. template_id: this.userTemplateId
  227. }
  228. //console.log(this.userTemplateId)
  229. //this.$route.query.website_id
  230. this.$store.dispatch('template/addWebsiteTemplateclassintel', data).then(res => {
  231. if (res.code != 200) {
  232. this.$message.error(res.message)
  233. } else {
  234. //this.$message.success('模板风格保存成功!');
  235. //保存模板风格成功,开始构建网站
  236. this.$router.push({
  237. path: '/templateCreat',
  238. query: {
  239. website_id: this.$route.query.website_id,
  240. style: 1
  241. }
  242. });
  243. }
  244. })
  245. }
  246. },
  247. //回显数据
  248. getUserTemplate() {
  249. this.$store.dispatch('template/getWebsiteTemplateclassintel', { website_id: this.$route.query.website_id }).then(res => {
  250. let that = this;
  251. if (res.code == 200) {
  252. for (let item of that.tableData) {
  253. if (item.id == res.data.tid) {
  254. item.status = 1;
  255. }
  256. }
  257. //给与所选缩略图
  258. this.userData = res.data.template_img;
  259. //给与所选id
  260. this.userTemplateId = res.data.tid;
  261. } else {
  262. this.$message.error(res.message)
  263. }
  264. })
  265. },
  266. //2.提交风格模板 end ------------------------------------------------------------>
  267. },
  268. mounted() {
  269. //给与网站id
  270. this.getApiData.website_id = this.$route.query.website_id;
  271. //获取所有风格
  272. this.getAllClass();
  273. //获取所有皮肤
  274. this.getData();
  275. }
  276. }
  277. </script>
  278. <style scoped lang="less">
  279. .searchBtnBox {
  280. padding-top: 26px;
  281. text-align: right;
  282. }
  283. .paginationBox {
  284. padding: 20px 0 0 0;
  285. text-align: center;
  286. }
  287. .btnBox {
  288. padding: 0 0 40px 0;
  289. text-align: center;
  290. }
  291. .thumbnailBox {
  292. display: flex;
  293. align-items: center;
  294. flex-wrap: wrap;
  295. justify-content: flex-start;
  296. .thumbnailItem {
  297. //width: 12.5%;
  298. width: 180px;
  299. height: 180px;
  300. text-align: center;
  301. padding: 0 10px 10px 10px;
  302. .thumbnailItemBox {
  303. background: #ECEFFD;
  304. border-radius: 10px;
  305. padding: 10px;
  306. position: relative;
  307. cursor: pointer;
  308. .thumbnailItemTitle {
  309. position: absolute;
  310. bottom: 10px;
  311. left: 10px;
  312. background: rgba(0, 0, 0, 0.5);
  313. color: #fff;
  314. font-size: 14px;
  315. text-align: center;
  316. padding: 5px 10px;
  317. border-radius: 4px;
  318. }
  319. }
  320. }
  321. img {
  322. width: 140px;
  323. height: 140px;
  324. display: block;
  325. }
  326. }
  327. .templateStyleBox {
  328. padding: 20px 20px 0 20px;
  329. background-color: #F5F7FB;
  330. display: flex;
  331. flex-wrap: wrap;
  332. .templateStyleItem {
  333. width: 20%;
  334. box-sizing: border-box;
  335. padding: 10px 10px 10px 10px;
  336. text-align: center;
  337. cursor: pointer;
  338. margin-bottom: 20px;
  339. .templateStyleItemBox {
  340. background: #fff;
  341. border-radius: 10px;
  342. padding: 20px 20px 0 20px;
  343. border-top: 5px solid #E9EDF7;
  344. border-bottom: 5px solid #E9EDF7;
  345. border-left: 1px solid #E9EDF7;
  346. border-right: 1px solid #E9EDF7;
  347. // &:hover {
  348. // border-top: 5px solid #E9EDF7;
  349. // border-bottom: 5px solid #E9EDF7;
  350. // border-left: 1px solid #E9EDF7;
  351. // border-right: 1px solid #E9EDF7;
  352. // }
  353. }
  354. .active {
  355. border-top: 5px solid #5570F1;
  356. border-bottom: 5px solid #5570F1;
  357. border-left: 1px solid #5570F1;
  358. border-right: 1px solid #5570F1;
  359. }
  360. .templateStyleItemTitle {
  361. font-size: 14px;
  362. color: #333;
  363. text-align: center;
  364. padding: 10px 0;
  365. }
  366. img {
  367. width: 100%;
  368. height: 340px;
  369. }
  370. }
  371. }
  372. .imgZoomBox {
  373. img {
  374. width: 100%;
  375. }
  376. }
  377. .alignCenterBox {
  378. text-align: center;
  379. }
  380. </style>