commonVue.js 8.2 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. 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'||window.location.pathname == '/')) {
  123. jQuery.ajax({
  124. type: 'POST',
  125. dataType: 'json',
  126. url: window.FQDN + 'Index/index',
  127. }).done(function (res) {
  128. // setTimeout(()=>{
  129. _this.loading = false;
  130. // },100)
  131. _this.homeList = res
  132. _this.status = true
  133. }).fail(function (err) {});
  134. }
  135. // 获取反馈弹框类型数据
  136. if (res.data[i].sname == '/solution/index.html') {
  137. _this.dialogDataArray = (res.data[i].children)
  138. _this.ruleForm.platName = _this.dialogDataArray[0].categoryName;
  139. }
  140. }
  141. })
  142. },
  143. //获取内容
  144. getArticalData(requestParams, type) {
  145. $.ajax({
  146. type: 'GET',
  147. dataType: 'json',
  148. url: window.FQDN2 + 'siteArticle/siteArticleList',
  149. data: requestParams
  150. }).done(function (res) {
  151. var aa
  152. var bb
  153. if(type==1){
  154. bb=res.data.records
  155. }else{
  156. aa= res.data.records;
  157. // aa.sort(_this.compare("sortindex"))
  158. _this.articalArray = aa;
  159. }
  160. if (bb) {
  161. _this.articalArrayRelated = bb.filter(obj => obj.id != _this.articalArray[0].id);
  162. console.log(_this.articalArrayRelated)
  163. }
  164. _this.loading = false;
  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. });