commonVue.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. var app = new Vue({
  2. el: '#app',
  3. data: {
  4. //公共
  5. id: null,
  6. columnList: [
  7. ],
  8. requestParams: { //内容接口请求参数
  9. categoryid: this.id,
  10. pageNum: 1,
  11. pageSize: 9,
  12. title: '',
  13. order:'sortindex',
  14. articleid:0,
  15. },
  16. currentPath: '',
  17. articalArray: [], //详情数组
  18. articalArrayRelated: [], //相关推荐
  19. columnTypes: [], //栏目类型
  20. colL:0,
  21. columnImage: '', //栏目图片
  22. // 公共弹框
  23. centerDialogVisible: false,
  24. dialogDataArray: [],
  25. ruleForm: {
  26. platName: '智慧安防',
  27. consultName: '',
  28. consultPhone: '',
  29. mail: '',
  30. company: '',
  31. consultContent: "",
  32. },
  33. rules: {
  34. platName: [{
  35. required: true,
  36. message: '请选择类型',
  37. trigger: 'change'
  38. }, ],
  39. consultName: [{
  40. required: true,
  41. message: '请输入姓名',
  42. trigger: 'blur'
  43. }, ],
  44. consultPhone: [{
  45. required: true,
  46. message: '请输入正确的电话号码',
  47. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  48. trigger: 'change'
  49. }],
  50. mail: [{
  51. required: false,
  52. type: "email",
  53. message: "请输入正确的邮箱地址",
  54. trigger: 'blur'
  55. }],
  56. },
  57. //首页
  58. homeList: [],
  59. status: false,
  60. // 新闻
  61. goPage: 1,
  62. totalPageNum: 1,
  63. totalPageSzie: 1,
  64. loading: true,
  65. categoryid: 0,
  66. },
  67. computed: {
  68. },
  69. created: function () {
  70. this.requestParams.categoryid = this.getQuery('id') ? this.getQuery('id') : ''
  71. this.requestParams.title = this.getQuery('title') ? this.getQuery('title') : ''
  72. this.requestParams.articleid = this.getQuery('articleid') ? this.getQuery('articleid') : ''
  73. },
  74. mounted: function () {
  75. _this = this
  76. this.getColumnData()
  77. },
  78. methods: {
  79. //获取栏目
  80. getColumnData() {
  81. this.columnTypes = []
  82. $.ajax({
  83. type: 'get',
  84. dataType: 'json',
  85. url: window.FQDN2 + 'siteCategory/siteCategoryList',
  86. }).done(function (res) {
  87. _this.columnList = res.data;
  88. _this.currentPath = window.location.pathname;
  89. for (let i = 0; i < res.data.length; i++) {
  90. //栏目处理
  91. if (res.data[i].sname == window.location.pathname) {
  92. //进入当前栏目页
  93. _this.columnTypes = res.data[i].children
  94. _this.colL= _this.columnTypes.childten;
  95. if (res.data[i].children.length > 0) {
  96. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  97. } else {
  98. _this.requestParams.categoryid = _this.getQuery('id')
  99. }
  100. _this.getArticalData(_this.requestParams)
  101. _this.columnImage = res.data[i].imagePath;
  102. } else {
  103. // 进入详情页
  104. if (res.data[i].sname == '/product/index.html' && window.location.pathname == '/product/read.html') {
  105. getDetailCommon()
  106. }
  107. if (res.data[i].sname == '/solution/index.html' && window.location.pathname == '/solution/read.html') {
  108. getDetailCommon()
  109. }
  110. if (res.data[i].sname == '/news/index.html' && window.location.pathname == '/news/read.html') {
  111. getDetailCommon()
  112. }
  113. function getDetailCommon(){
  114. //获取内容详情
  115. _this.getArticalData(_this.requestParams)
  116. //获取详情相关数据
  117. setTimeout(() => {
  118. _this.requestParams.title = ''
  119. _this.requestParams.articleid = 0
  120. _this.getArticalData(_this.requestParams, 1)
  121. }, 100)
  122. _this.currentPath = res.data[i].sname //产品详情时栏目高亮
  123. _this.columnImage = res.data[i].imagePath; //栏目图片获取
  124. }
  125. }
  126. //首页旧
  127. if (res.data[i].sname == '/index.html' && (window.location.pathname == '/index.html'||window.location.pathname == '/')) {
  128. jQuery.ajax({
  129. type: 'POST',
  130. dataType: 'json',
  131. url: window.FQDN + 'Index/index',
  132. }).done(function (res) {
  133. // setTimeout(()=>{
  134. _this.loading = false;
  135. // },100)
  136. _this.homeList = res
  137. _this.status = true
  138. }).fail(function (err) {});
  139. }
  140. // 获取反馈弹框类型数据
  141. if (res.data[i].sname == '/solution/index.html') {
  142. _this.dialogDataArray = (res.data[i].children)
  143. _this.ruleForm.platName = _this.dialogDataArray[0].categoryName;
  144. }
  145. }
  146. })
  147. },
  148. //获取内容
  149. getArticalData(requestParams, type) {
  150. $.ajax({
  151. type: 'GET',
  152. dataType: 'json',
  153. url: window.FQDN2 + 'siteArticle/siteArticleList',
  154. data: requestParams
  155. }).done(function (res) {
  156. var aa
  157. var bb
  158. if(type==1){
  159. bb=res.data.records
  160. }else{
  161. aa= res.data.records;
  162. // aa.sort(_this.compare("sortindex"))
  163. _this.articalArray = aa;
  164. }
  165. if (bb) {
  166. console.log(bb)
  167. console.log(_this.articalArray[0])
  168. _this.articalArrayRelated = bb.filter(obj => obj.title != _this.articalArray[0].title);
  169. // _this.articalArrayRelated = bb
  170. console.log(_this.articalArrayRelated)
  171. }
  172. _this.loading = false;
  173. _this.totalPageSzie = res.data.total
  174. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  175. }).fail(function (err) {});
  176. },
  177. //类型点击
  178. facilityClick(e, item) {
  179. this.requestParams.categoryid = item.id
  180. this.requestParams.pageNum = 1
  181. this.getArticalData(this.requestParams)
  182. },
  183. // 分页
  184. oneInnerBox: function (param) {
  185. window.location = "./read.html?id=" + param.categoryid + "&title=" + param.title + "&articleid=" + param.id + "&isUrlId=1";
  186. },
  187. enterPage: function (res) {
  188. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  189. this.requestParams.pageNum = this.goPage
  190. this.getArticalData(this.requestParams)
  191. } else {
  192. this.goPage = 1
  193. alert('输入页数有误!')
  194. }
  195. },
  196. currentChange: function (res) {
  197. this.requestParams.pageNum = res
  198. this.getArticalData(this.requestParams)
  199. },
  200. //首页
  201. scrollToTop() {
  202. window.scrollTo({
  203. top: 0,
  204. behavior: "smooth"
  205. });
  206. },
  207. //公共弹框
  208. submitForm(formName) {
  209. _this = this
  210. this.$refs[formName].validate((valid) => {
  211. if (valid) {
  212. console.log(_this.ruleForm)
  213. let param = JSON.stringify(_this.ruleForm)
  214. jQuery.ajax({
  215. type: 'POST',
  216. // dataType: 'json',
  217. contentType: 'application/json;charset=UTF-8',
  218. url: window.FQDN2 + 'siteReview',
  219. data: param
  220. }).done(function (res) {
  221. if (res.status === "SUCCESS") {
  222. _this.$message({
  223. message: '提交成功',
  224. type: 'success'
  225. });
  226. _this.centerDialogVisible = false
  227. _this.$refs[formName].resetFields(); //重置from校验
  228. }
  229. }).fail(function (err) {});
  230. } else {
  231. console.log('error submit!!');
  232. return false;
  233. }
  234. });
  235. },
  236. resetForm(formName) {
  237. this.$refs[formName].resetFields();
  238. this.centerDialogVisible = false
  239. },
  240. // 排序
  241. compare(property) {
  242. return function (a, b) {
  243. var value1 = a[property];
  244. var value2 = b[property];
  245. return value1 - value2;
  246. }
  247. },
  248. // 获取路由参数
  249. getQuery(name) {
  250. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  251. var r = window.location.search.substr(1).match(reg);
  252. if (r != null) return decodeURI(r[2]);
  253. return null;
  254. },
  255. //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23
  256. timeFormatSeconds(time) {
  257. var d = time ? new Date(time) : new Date();
  258. var year = d.getFullYear();
  259. var month = d.getMonth() + 1;
  260. var day = d.getDate();
  261. var hours = d.getHours();
  262. var min = d.getMinutes();
  263. var seconds = d.getSeconds();
  264. if (month < 10) month = '0' + month;
  265. if (day < 10) day = '0' + day;
  266. if (hours < 0) hours = '0' + hours;
  267. if (min < 10) min = '0' + min;
  268. if (seconds < 10) seconds = '0' + seconds;
  269. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  270. }
  271. }
  272. });