commonVue.js 8.5 KB

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