commonVue.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. for (let i = 0; i < res.data.length; i++) {
  87. //栏目处理
  88. if (res.data[i].sname == window.location.pathname) {
  89. //进入当前栏目页
  90. _this.columnTypes = res.data[i].children
  91. if (res.data[i].children.length > 0) {
  92. _this.requestParams.categoryid = (_this.getQuery('isUrlId') == 1) ? _this.getQuery('id') : _this.columnTypes[0].id;
  93. } else {
  94. _this.requestParams.categoryid = _this.getQuery('id')
  95. }
  96. _this.getArticalData(_this.requestParams)
  97. _this.columnImage = res.data[i].imagePath;
  98. } else {
  99. // 进入详情页
  100. if (res.data[i].sname == '/product/index.html' && window.location.pathname == '/product/read.html') {
  101. getDetailCommon()
  102. }
  103. if (res.data[i].sname == '/solution/index.html' && window.location.pathname == '/solution/read.html') {
  104. getDetailCommon()
  105. }
  106. if (res.data[i].sname == '/news/index.html' && window.location.pathname == '/news/read.html') {
  107. getDetailCommon()
  108. }
  109. function getDetailCommon(){
  110. //获取内容详情
  111. _this.getArticalData(_this.requestParams)
  112. //获取详情相关数据
  113. setTimeout(() => {
  114. _this.requestParams.title = ''
  115. _this.getArticalData(_this.requestParams, 1)
  116. }, 1)
  117. _this.currentPath = res.data[i].sname //产品详情时栏目高亮
  118. _this.columnImage = res.data[i].imagePath; //栏目图片获取
  119. }
  120. }
  121. //首页旧
  122. if (res.data[i].sname == '/index.html' && window.location.pathname == '/index.html') {
  123. jQuery.ajax({
  124. type: 'POST',
  125. dataType: 'json',
  126. url: window.FQDN + 'Index/index',
  127. }).done(function (res) {
  128. _this.homeList = res
  129. _this.status = true
  130. }).fail(function (err) {});
  131. }
  132. // 获取反馈弹框类型数据
  133. if (res.data[i].sname == '/solution/index.html') {
  134. _this.dialogDataArray = (res.data[i].children)
  135. _this.ruleForm.platName = _this.dialogDataArray[0].categoryName;
  136. }
  137. }
  138. })
  139. },
  140. //获取内容
  141. getArticalData(requestParams, type) {
  142. $.ajax({
  143. type: 'GET',
  144. dataType: 'json',
  145. url: window.FQDN2 + 'siteArticle/siteArticleList',
  146. data: requestParams
  147. }).done(function (res) {
  148. var aa
  149. var bb
  150. if(type==1){
  151. bb=res.data.records
  152. }else{
  153. aa= res.data.records;
  154. // aa.sort(_this.compare("sortindex"))
  155. _this.articalArray = aa;
  156. }
  157. if (bb) {
  158. _this.articalArrayRelated = bb.filter(obj => obj.id != _this.articalArray[0].id);
  159. console.log(_this.articalArrayRelated)
  160. }
  161. // setTimeout(()=>{
  162. _this.loading = false;
  163. // },100)
  164. _this.totalPageSzie = res.data.total
  165. _this.totalPageNum = Math.ceil(res.data.total / res.data.size);
  166. }).fail(function (err) {});
  167. },
  168. //类型点击
  169. facilityClick(e, item) {
  170. this.requestParams.categoryid = item.id
  171. this.requestParams.pageNum = 1
  172. this.getArticalData(this.requestParams)
  173. },
  174. // 分页
  175. oneInnerBox: function (param) {
  176. window.location = "./read.html?id=" + param.categoryid + "&title=" + param.title + "&isUrlId=1";
  177. },
  178. enterPage: function (res) {
  179. if (this.goPage >= 1 && this.goPage <= this.totalPageNum) {
  180. this.requestParams.pageNum = this.goPage
  181. this.getArticalData(this.requestParams)
  182. } else {
  183. this.goPage = 1
  184. alert('输入页数有误!')
  185. }
  186. },
  187. currentChange: function (res) {
  188. this.requestParams.pageNum = res
  189. this.getArticalData(this.requestParams)
  190. },
  191. //首页
  192. scrollToTop() {
  193. window.scrollTo({
  194. top: 0,
  195. behavior: "smooth"
  196. });
  197. },
  198. //公共弹框
  199. submitForm(formName) {
  200. _this = this
  201. this.$refs[formName].validate((valid) => {
  202. if (valid) {
  203. console.log(_this.ruleForm)
  204. let param = JSON.stringify(_this.ruleForm)
  205. jQuery.ajax({
  206. type: 'POST',
  207. // dataType: 'json',
  208. contentType: 'application/json;charset=UTF-8',
  209. url: window.FQDN2 + 'siteReview',
  210. data: param
  211. }).done(function (res) {
  212. if (res.status === "SUCCESS") {
  213. _this.$message({
  214. message: '提交成功',
  215. type: 'success'
  216. });
  217. _this.centerDialogVisible = false
  218. _this.$refs[formName].resetFields(); //重置from校验
  219. }
  220. }).fail(function (err) {});
  221. } else {
  222. console.log('error submit!!');
  223. return false;
  224. }
  225. });
  226. },
  227. resetForm(formName) {
  228. this.$refs[formName].resetFields();
  229. this.centerDialogVisible = false
  230. },
  231. // 排序
  232. compare(property) {
  233. return function (a, b) {
  234. var value1 = a[property];
  235. var value2 = b[property];
  236. return value1 - value2;
  237. }
  238. },
  239. // 获取路由参数
  240. getQuery(name) {
  241. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  242. var r = window.location.search.substr(1).match(reg);
  243. if (r != null) return decodeURI(r[2]);
  244. return null;
  245. },
  246. //获得年月日时分秒 //传入日期//例:2020-10-27T14:36:23
  247. timeFormatSeconds(time) {
  248. var d = time ? new Date(time) : new Date();
  249. var year = d.getFullYear();
  250. var month = d.getMonth() + 1;
  251. var day = d.getDate();
  252. var hours = d.getHours();
  253. var min = d.getMinutes();
  254. var seconds = d.getSeconds();
  255. if (month < 10) month = '0' + month;
  256. if (day < 10) day = '0' + day;
  257. if (hours < 0) hours = '0' + hours;
  258. if (min < 10) min = '0' + min;
  259. if (seconds < 10) seconds = '0' + seconds;
  260. return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
  261. }
  262. }
  263. });