commonVue.js 8.1 KB

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