commonVue.js 8.3 KB

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