library.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. <template>
  2. <div class="library_box" :style="'height:' + fullHeight + 'px'">
  3. <!-- 页头 -->
  4. <div class="library_box_headr">
  5. <el-page-header title @back="goBack" content="知识库"></el-page-header>
  6. <img src="../../assets/imageOne/sou.png" @click="sousuo()" alt class="library_box_headr_sou" />
  7. </div>
  8. <!-- 主内容 -->
  9. <div class="library_box_main">
  10. <!-- tab切换 -->
  11. <ul class="library_box_main_tab">
  12. <li
  13. class="main_tab_plant"
  14. v-for="(item,index) in items"
  15. :key="index"
  16. :class="{active:istrue==index}"
  17. @click="istrue=index, qingqiu(index)"
  18. >{{ item.name }}</li>
  19. </ul>
  20. <!-- 列表 -->
  21. <mescroll-vue ref="mescroll" :down="mescrollDown" :up="mescrollUp" @init="mescrollInit">
  22. <ul class="library_box_main_ul" v-if="axiosShow">
  23. <li
  24. class="library_box_main_li"
  25. @click="listAdd($event, index, item.id, item.name)"
  26. v-for="(item, index) in this.redata"
  27. :key="index"
  28. >
  29. <div class="library_box_main_li_box">
  30. <!-- 图片 -->
  31. <img
  32. :src="item.img_urls === null || item.img_urls === '' ? './static/picture.jpg' : item.img_urls"
  33. alt
  34. class="library_box_main_li_img"
  35. />
  36. <!-- 病虫害名称 -->
  37. <div class="library_box_main_li_name">
  38. <div class="library_box_main_li_name_text">{{ item.name | ellipsis }}</div>
  39. <div class="library_box_main_li_name_xiqng">{{ item.prevention | ellipsis }}</div>
  40. </div>
  41. <!-- 详情 -->
  42. <div class="library_box_main_li_btn">
  43. <span class="library_box_main_li_btn_text">详情</span>
  44. <img src="../../assets/imageOne/right.png" alt class="library_box_main_li_btn_del" />
  45. </div>
  46. </div>
  47. </li>
  48. </ul>
  49. <!-- 暂空判断 -->
  50. <div class="library_judge" v-else>
  51. <img src="../../assets/imageOne/wu.png" alt class="library_judge_img" />
  52. <div class="library_judge_text">抱歉,暂无此数据</div>
  53. </div>
  54. </mescroll-vue>
  55. <!-- 搜索弹框-->
  56. <el-dialog title="搜索" :visible.sync="dialogVisible" width="80%">
  57. <el-input
  58. @blur="animateWidthA()"
  59. @focus="animateWidth()"
  60. placeholder="请输入搜索内容"
  61. v-model="input"
  62. clearable
  63. ></el-input>
  64. <span slot="footer" class="dialog-footer">
  65. <div class="system-box_div">
  66. <!-- 测试 -->
  67. <el-button @click="dialogVisible = false" class="kunchongBtn">取 消</el-button>
  68. </div>
  69. <div class="system-box_div">
  70. <!-- 测试 -->
  71. <el-button @click="dialogVisible = false, search()" class="binghaiBtn">确 定</el-button>
  72. </div>
  73. </span>
  74. </el-dialog>
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. // 引入mescroll的vue组件
  80. import MescrollVue from "mescroll.js/mescroll.vue";
  81. export default {
  82. //import引入的组件需要注入到对象中才能使用
  83. components: {
  84. MescrollVue // 注册mescroll组件
  85. },
  86. //限时数据文本的字数限时
  87. filters: {
  88. ellipsis(value) {
  89. if (!value) return "";
  90. if (value.length > 5) {
  91. return value.slice(0, 5) + "...";
  92. }
  93. return value;
  94. }
  95. },
  96. inject: ["reload"], //注入reload方法
  97. data() {
  98. return {
  99. msg: "hello world",
  100. fullHeight: document.documentElement.clientHeight,
  101. istrue: localStorage.getItem("quebie"),
  102. items: [{ name: "虫害" }, { name: "病害" }],
  103. redata: [], //数据
  104. dialogVisible: false, //搜索弹框
  105. input: "", //搜索值
  106. axiosShow: true, //暂空判断
  107. sousuoData: "", //搜索数据标识
  108. iptShow: true, //搜索框呈现效果
  109. //上拉加载下拉刷新
  110. mescroll: null, // mescroll实例对象
  111. mescrollDown: {}, //下拉刷新的配置. (如果下拉刷新和上拉加载处理的逻辑是一样的,则mescrollDown可不用写了)
  112. mescrollUp: {
  113. // 上拉加载的配置.
  114. callback: this.upCallback, // 上拉回调,此处简写; 相当于 callback: function(page, mescroll) { }
  115. //以下是一些常用的配置,当然不写也可以的.
  116. page: {
  117. num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
  118. size: 6 //每页数据条数,默认10
  119. },
  120. isBounce: true, //根据记录的滚动条高度回弹
  121. htmlNodata: '<p class="upwarp-nodata">-- 已经到底了! --</p>',
  122. noMoreSize: 6, //如果列表已无数据,可设置列表的总数量要大于5才显示无更多数据;
  123. // 避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
  124. // 这就是为什么无更多数据有时候不显示的原因
  125. toTop: {
  126. //回到顶部按钮
  127. // src: "../../../static/gotop.png", //图片路径,默认null,支持网络图
  128. src:
  129. "http://pic.51yuansu.com/pic3/cover/00/65/23/5896fa4bc81fc_610.jpg", //图片路径,默认null,支持网络图
  130. offset: 800 //列表滚动1000px才显示回到顶部按钮
  131. },
  132. empty: {
  133. //列表第一页无任何数据时,显示的空提示布局; 需配置warpId才显示
  134. warpId: "", //父布局的id (1.3.5版本支持传入dom元素)
  135. icon: "./static/mescroll/mescroll-empty.png", //图标,默认null,支持网络图
  136. tip: "暂无相关数据~" //提示
  137. },
  138. onScroll: function(mescroll, y, isUp) {
  139. //监听滚动条
  140. // console.log(y);
  141. },
  142. lazyLoad: {
  143. use: true // 是否开启懒加载,默认false
  144. }
  145. },
  146. aggregate: "" //后端传来数据的总条数
  147. };
  148. },
  149. beforeRouteEnter(to, from, next) {
  150. // 如果没有配置顶部按钮或isBounce,则beforeRouteEnter不用写
  151. next(vm => {
  152. // 滚动到原来的列表位置,恢复顶部按钮和isBounce的配置
  153. vm.$refs.mescroll && vm.$refs.mescroll.beforeRouteEnter();
  154. });
  155. },
  156. beforeRouteLeave(to, from, next) {
  157. // 如果没有配置顶部按钮或isBounce,则beforeRouteLeave不用写
  158. // 记录列表滚动的位置,隐藏顶部按钮和isBounce的配置
  159. this.$refs.mescroll && this.$refs.mescroll.beforeRouteLeave();
  160. next();
  161. },
  162. computed: {},
  163. //监控data中的数据变化
  164. watch: {
  165. fullHeight(val) {
  166. //监控浏览器高度变化
  167. if (!this.timer) {
  168. this.fullHeight = val;
  169. this.timer = true;
  170. let that = this;
  171. setTimeout(function() {
  172. //防止过度调用监测事件,导致卡顿
  173. that.timer = false;
  174. }, 400);
  175. }
  176. },
  177. //监听搜索弹框的状态
  178. dialogVisible(val) {
  179. if (val === false) {
  180. this.input = "";
  181. }
  182. }
  183. },
  184. mounted() {
  185. let _this = this;
  186. _this.get_boderHeight();
  187. //判断如果biaoshi为空的话就存否则不存
  188. if (localStorage.getItem("quebie") === null) {
  189. localStorage.setItem("quebie", "0");
  190. }
  191. if (localStorage.getItem("quebie") === "0") {
  192. //判断是否是搜索数据
  193. if (localStorage.getItem("sousuoData") !== null) {
  194. let postData = _this.$qs.parse({
  195. name: localStorage.getItem("libraryIpt"),
  196. ret: "insect",
  197. page: localStorage.getItem("libraryPage")
  198. });
  199. _this
  200. .$axios({
  201. method: "get",
  202. url: "bigservers/insect_base?page=1"
  203. })
  204. .then(res => {
  205. if (res.data === 0) {
  206. _this.axiosShow = false;
  207. _this.FenShow = false;
  208. } else if (res.data !== 0) {
  209. _this.redata = res.data.dat;
  210. _this.FenShow = true;
  211. let a = res.data.page;
  212. let b = "5";
  213. let d = a / b;
  214. if (d % 1 === 0) {
  215. _this.page = d * 10;
  216. } else {
  217. let g = Math.ceil(d) * 10;
  218. _this.page = g;
  219. }
  220. }
  221. })
  222. .catch(error => {
  223. console.log(error);
  224. });
  225. } else if (localStorage.getItem("sousuoData") === null) {
  226. _this
  227. .$axios({
  228. method: "get",
  229. url: "bigservers/insect_base?page=1"
  230. })
  231. .then(res => {
  232. if (res.data === 0) {
  233. _this.axiosShow = false;
  234. _this.FenShow = false;
  235. } else if (res.data !== 0) {
  236. _this.redata = res.data.dat;
  237. _this.FenShow = true;
  238. let a = res.data.page;
  239. let b = "5";
  240. let d = a / b;
  241. if (d % 1 === 0) {
  242. _this.page = d * 10;
  243. } else {
  244. let g = Math.ceil(d) * 10;
  245. _this.page = g;
  246. }
  247. }
  248. })
  249. .catch(error => {
  250. console.log(error);
  251. });
  252. }
  253. } else if (localStorage.getItem("quebie") === "1") {
  254. _this
  255. .$axios({
  256. method: "get",
  257. url: "bigservers/plant_base?page=1"
  258. })
  259. .then(res => {
  260. if (res.data === 0) {
  261. _this.FenShow = false;
  262. _this.axiosShow = false;
  263. } else if (res.data !== 0) {
  264. _this.FenShow = true;
  265. _this.redata = res.data.dat;
  266. let a = res.data.page;
  267. let b = "5";
  268. let d = a / b;
  269. if (d % 1 === 0) {
  270. _this.page = d * 10;
  271. } else {
  272. let g = Math.ceil(d) * 10;
  273. _this.page = g;
  274. }
  275. }
  276. })
  277. .catch(error => {
  278. console.log(error);
  279. });
  280. }
  281. },
  282. methods: {
  283. mescrollInit(mescroll) {
  284. this.mescroll = mescroll; // 如果this.mescroll对象没有使用到,则mescrollInit可以不用配置
  285. },
  286. // 上拉回调 page = {num:1, size:10}; num:当前页 ,默认从1开始; size:每页数据条数,默认10
  287. upCallback(page, mescroll) {
  288. let _this = this;
  289. if (localStorage.getItem("quebie") === "0") {
  290. //判断是否是搜索数据
  291. if (localStorage.getItem("sousuoData") !== null) {
  292. if (localStorage.getItem("quebie") === "0") {
  293. var aaa = "insect";
  294. } else if (localStorage.getItem("quebie") === "1") {
  295. var aaa = "plant";
  296. }
  297. localStorage.setItem("libraryPage", this.mescrollUp.page.num); // 存当前页数
  298. let postData = _this.$qs.parse({
  299. name: localStorage.getItem("libraryIpt"),
  300. ret: aaa,
  301. page: this.mescrollUp.page.num
  302. });
  303. _this
  304. .$axios({
  305. method: "post",
  306. url: "bigservers/search",
  307. data: postData,
  308. headers: {
  309. "Content-Type": "application/json"
  310. }
  311. })
  312. .then(res => {
  313. //判断data中的变量是否为空 ,为空的话存后端发来的总条数
  314. if (this.aggregate === "") {
  315. //存变量
  316. this.aggregate = res.data.num;
  317. var b = "6";
  318. this.aggregate = this.aggregate / b;
  319. this.aggregate = Math.ceil(this.aggregate); //将小数点转换为整数
  320. }
  321. if (this.mescrollUp.page.num <= this.aggregate) {
  322. let postData = _this.$qs.parse({
  323. name: localStorage.getItem("libraryIpt"),
  324. ret: aaa,
  325. page: this.mescrollUp.page.num
  326. });
  327. this.$axios({
  328. method: "post",
  329. url: "bigservers/search",
  330. data: postData,
  331. headers: {
  332. "Content-Type": "application/json"
  333. }
  334. })
  335. .then(res => {
  336. let arr = res.data.dat;
  337. // 如果是第一页需手动置空列表
  338. if (page.num === 1) this.redata = [];
  339. // 把请求到的数据添加到列表
  340. this.redata = this.redata.concat(arr);
  341. // 数据渲染成功后,隐藏下拉刷新的状态
  342. this.$nextTick(() => {
  343. mescroll.endSuccess(arr.length);
  344. });
  345. if (res.data.num === 0) {
  346. _this.axiosShow = false;
  347. _this.FenShow = false;
  348. } else if (res.data.num !== 0) {
  349. _this.axiosShow = true;
  350. _this.FenShow = true;
  351. }
  352. })
  353. .catch(error => {
  354. mescroll.endErr();
  355. });
  356. } else if (this.mescrollUp.page.num > this.aggregate) {
  357. // 数据渲染成功后,隐藏下拉刷新的状态
  358. this.$nextTick(() => {
  359. mescroll.endSuccess(this.aggregate);
  360. });
  361. }
  362. if (this.aggregate === 0) {
  363. this.axiosShow = false;
  364. this.FenShow = false;
  365. }
  366. localStorage.setItem("sousuoData", res.data.dat[0].req); //将搜索数据标识存在data中
  367. })
  368. .catch(error => {
  369. mescroll.endErr();
  370. });
  371. } else if (localStorage.getItem("sousuoData") === null) {
  372. //虫害
  373. this.$axios({
  374. method: "get",
  375. url: "bigservers/insect_base",
  376. params: {
  377. page: this.mescrollUp.page.num
  378. }
  379. })
  380. .then(res => {
  381. //判断data中的变量是否为空 ,为空的话存后端发来的总条数
  382. if (this.aggregate === "") {
  383. //存变量
  384. this.aggregate = res.data.num;
  385. var b = "6";
  386. this.aggregate = this.aggregate / b;
  387. this.aggregate = Math.ceil(this.aggregate); //将小数点转换为整数
  388. }
  389. //删除了默认的每页条数后判断数是否大于页码
  390. if (this.mescrollUp.page.num <= this.aggregate) {
  391. this.$axios({
  392. method: "get",
  393. url: "bigservers/insect_base",
  394. params: {
  395. page: this.mescrollUp.page.num
  396. }
  397. })
  398. .then(res => {
  399. let arr = res.data.dat;
  400. // 如果是第一页需手动置空列表
  401. if (page.num === 1) this.redata = [];
  402. // 把请求到的数据添加到列表
  403. this.redata = this.redata.concat(arr);
  404. // 数据渲染成功后,隐藏下拉刷新的状态
  405. this.$nextTick(() => {
  406. mescroll.endSuccess(arr.length);
  407. });
  408. if (res.data.num === 0) {
  409. _this.axiosShow = false;
  410. _this.FenShow = false;
  411. } else if (res.data.num !== 0) {
  412. _this.axiosShow = true;
  413. _this.FenShow = true;
  414. }
  415. })
  416. .catch(error => {
  417. mescroll.endErr();
  418. });
  419. } else if (this.mescrollUp.page.num > this.aggregate) {
  420. // 数据渲染成功后,隐藏下拉刷新的状态
  421. this.$nextTick(() => {
  422. mescroll.endSuccess(this.aggregate);
  423. });
  424. }
  425. if (this.aggregate === 0) {
  426. this.axiosShow = false;
  427. this.FenShow = false;
  428. }
  429. // let arr = res.data.dat;
  430. // // console.log(arr);
  431. // // 如果是第一页需手动置空列表
  432. // if (page.num === 1) this.redata = [];
  433. // // 把请求到的数据添加到列表
  434. // this.redata = this.redata.concat(arr);
  435. // // 数据渲染成功后,隐藏下拉刷新的状态
  436. // this.$nextTick(() => {
  437. // mescroll.endSuccess(arr.length);
  438. // });
  439. })
  440. .catch(error => {
  441. mescroll.endErr();
  442. });
  443. }
  444. } else if (localStorage.getItem("quebie") === "1") {
  445. //判断是否在搜索情况下
  446. if (localStorage.getItem("sousuoData") !== null) {
  447. if (localStorage.getItem("quebie") === "0") {
  448. var aaa = "insect";
  449. } else if (localStorage.getItem("quebie") === "1") {
  450. var aaa = "plant";
  451. }
  452. localStorage.setItem("libraryPage", this.mescrollUp.page.num); // 存当前页数
  453. let postData = _this.$qs.parse({
  454. name: localStorage.getItem("libraryIpt"),
  455. ret: aaa,
  456. page: this.mescrollUp.page.num
  457. });
  458. _this
  459. .$axios({
  460. method: "post",
  461. url: "bigservers/search",
  462. data: postData,
  463. headers: {
  464. "Content-Type": "application/json"
  465. }
  466. })
  467. .then(res => {
  468. //判断data中的变量是否为空 ,为空的话存后端发来的总条数
  469. if (this.aggregate === "") {
  470. //存变量
  471. this.aggregate = res.data.num;
  472. var b = "6";
  473. this.aggregate = this.aggregate / b;
  474. this.aggregate = Math.ceil(this.aggregate); //将小数点转换为整数
  475. }
  476. //删除了默认的每页条数后判断数是否大于页码
  477. if (this.mescrollUp.page.num <= this.aggregate) {
  478. let postData = _this.$qs.parse({
  479. name: localStorage.getItem("libraryIpt"),
  480. ret: aaa,
  481. page: this.mescrollUp.page.num
  482. });
  483. this.$axios({
  484. method: "post",
  485. url: "bigservers/search",
  486. data: postData,
  487. headers: {
  488. "Content-Type": "application/json"
  489. }
  490. })
  491. .then(res => {
  492. let arr = res.data.dat;
  493. // 如果是第一页需手动置空列表
  494. if (page.num === 1) this.redata = [];
  495. // 把请求到的数据添加到列表
  496. this.redata = this.redata.concat(arr);
  497. // 数据渲染成功后,隐藏下拉刷新的状态
  498. this.$nextTick(() => {
  499. mescroll.endSuccess(arr.length);
  500. });
  501. if (res.data.num === 0) {
  502. _this.axiosShow = false;
  503. _this.FenShow = false;
  504. } else if (res.data.num !== 0) {
  505. _this.axiosShow = true;
  506. _this.FenShow = true;
  507. }
  508. })
  509. .catch(error => {
  510. mescroll.endErr();
  511. });
  512. } else if (this.mescrollUp.page.num > this.aggregate) {
  513. // 数据渲染成功后,隐藏下拉刷新的状态
  514. this.$nextTick(() => {
  515. mescroll.endSuccess(this.aggregate);
  516. });
  517. }
  518. if (this.aggregate === 0) {
  519. this.axiosShow = false;
  520. this.FenShow = false;
  521. }
  522. // let arr = res.data.dat;
  523. // // 如果是第一页需手动置空列表
  524. // if (page.num === 1) this.redata = [];
  525. // // 把请求到的数据添加到列表
  526. // this.redata = this.redata.concat(arr);
  527. // // 数据渲染成功后,隐藏下拉刷新的状态
  528. // this.$nextTick(() => {
  529. // mescroll.endSuccess(arr.length);
  530. // });
  531. localStorage.setItem("sousuoData", res.data.dat[0].req); //将搜索数据标识存在data中
  532. })
  533. .catch(error => {
  534. mescroll.endErr();
  535. });
  536. } else if (localStorage.getItem("sousuoData") === null) {
  537. //病害
  538. this.$axios({
  539. method: "get",
  540. url: "bigservers/plant_base",
  541. params: {
  542. page: this.mescrollUp.page.num
  543. }
  544. })
  545. .then(res => {
  546. //判断data中的变量是否为空 ,为空的话存后端发来的总条数
  547. if (this.aggregate === "") {
  548. //存变量
  549. this.aggregate = res.data.num;
  550. var b = "6";
  551. this.aggregate = this.aggregate / b;
  552. this.aggregate = Math.ceil(this.aggregate); //将小数点转换为整数
  553. }
  554. //删除了默认的每页条数后判断数是否大于页码
  555. if (this.mescrollUp.page.num <= this.aggregate) {
  556. this.$axios({
  557. method: "get",
  558. url: "bigservers/plant_base",
  559. params: {
  560. page: this.mescrollUp.page.num
  561. }
  562. })
  563. .then(res => {
  564. let arr = res.data.dat;
  565. // 如果是第一页需手动置空列表
  566. if (page.num === 1) this.redata = [];
  567. // 把请求到的数据添加到列表
  568. this.redata = this.redata.concat(arr);
  569. // 数据渲染成功后,隐藏下拉刷新的状态
  570. this.$nextTick(() => {
  571. mescroll.endSuccess(arr.length);
  572. });
  573. if (res.data.num === 0) {
  574. _this.axiosShow = false;
  575. _this.FenShow = false;
  576. } else if (res.data.num !== 0) {
  577. _this.axiosShow = true;
  578. _this.FenShow = true;
  579. }
  580. })
  581. .catch(error => {
  582. mescroll.endErr();
  583. });
  584. } else if (this.mescrollUp.page.num > this.aggregate) {
  585. // 数据渲染成功后,隐藏下拉刷新的状态
  586. this.$nextTick(() => {
  587. mescroll.endSuccess(this.aggregate);
  588. });
  589. }
  590. if (this.aggregate === 0) {
  591. this.axiosShow = false;
  592. this.FenShow = false;
  593. }
  594. // let arr = res.data.dat;
  595. // // 如果是第一页需手动置空列表
  596. // if (page.num === 1) this.redata = [];
  597. // // 把请求到的数据添加到列表
  598. // this.redata = this.redata.concat(arr);
  599. // // 数据渲染成功后,隐藏下拉刷新的状态
  600. // this.$nextTick(() => {
  601. // mescroll.endSuccess(arr.length);
  602. // });
  603. })
  604. .catch(error => {
  605. mescroll.endErr();
  606. });
  607. }
  608. }
  609. },
  610. //动态获取浏览器高度
  611. get_boderHeight() {
  612. const that = this;
  613. window.onresize = () => {
  614. return (() => {
  615. window.fullHeight = document.documentElement.clientHeight;
  616. that.fullHeight = window.fullHeight;
  617. })();
  618. };
  619. },
  620. //点击返回系统设置
  621. goBack() {
  622. let _this = this;
  623. localStorage.removeItem("quebie");
  624. localStorage.removeItem("libraryID");
  625. localStorage.removeItem("libraryPage");
  626. localStorage.removeItem("sousuoData");
  627. localStorage.removeItem("libraryIpt");
  628. _this.$router.push("/discern");
  629. },
  630. //tab切换请求相应的数据
  631. qingqiu(index) {
  632. let _this = this;
  633. //判断当前点击的是虫害还是病害
  634. localStorage.setItem("quebie", index);
  635. // location.reload();
  636. // _this.reload();
  637. if (index === 0) {
  638. localStorage.removeItem("sousuoData");
  639. _this
  640. .$axios({
  641. method: "get",
  642. url: "bigservers/insect_base?page=1"
  643. })
  644. .then(res => {
  645. // this.reload();
  646. if (res.data.num === 0) {
  647. _this.axiosShow = false;
  648. } else if (res.data !== 0) {
  649. _this.axiosShow = true;
  650. _this.redata = res.data.dat;
  651. _this.FenShow = false;
  652. let a = res.data.page;
  653. let b = "5";
  654. let d = a / b;
  655. if (d % 1 === 0) {
  656. } else {
  657. let g = Math.ceil(d) * 10;
  658. // console.log(g);
  659. _this.page = g;
  660. }
  661. _this.FenShow = true;
  662. }
  663. })
  664. .catch(error => {
  665. console.log(error);
  666. });
  667. localStorage.removeItem("libraryPage"); //切换删除存在本地的当前页数
  668. } else if (index === 1) {
  669. localStorage.removeItem("sousuoData");
  670. _this
  671. .$axios({
  672. method: "get",
  673. url: "bigservers/plant_base?page=1"
  674. })
  675. .then(res => {
  676. if (res.data.num === 0) {
  677. _this.axiosShow = false;
  678. _this.FenShow = false;
  679. } else if (res.data.num !== 0) {
  680. _this.axiosShow = true;
  681. _this.redata = res.data.dat;
  682. let a = res.data.page;
  683. let b = "5";
  684. let d = a / b;
  685. if (d % 1 === 0) {
  686. } else {
  687. let g = Math.ceil(d) * 10;
  688. _this.page = g;
  689. }
  690. _this.FenShow = true;
  691. }
  692. })
  693. .catch(error => {
  694. console.log(error);
  695. });
  696. localStorage.removeItem("libraryPage"); //切换删除存在本地的当前页数
  697. }
  698. },
  699. //获取到当前li的id
  700. listAdd(e, index, id, name) {
  701. let _this = this;
  702. if (
  703. e.target.className === "library_box_main_li_btn_text" ||
  704. e.target.className === "library_box_main_li_btn_del" ||
  705. e.target.className === "library_box_main_li_btn" ||
  706. e.target.className === "library_box_main_li_img" ||
  707. e.target.className === "library_box_main_li_name" ||
  708. e.target.className === "library_box_main_li_name_text" ||
  709. e.target.className === "library_box_main_li_box"
  710. ) {
  711. _this.current = index;
  712. //获取点击对象
  713. let el = e.currentTarget;
  714. let listId = id;
  715. localStorage.setItem("libraryID", listId);
  716. _this.$router.push("/inventory");
  717. }
  718. },
  719. //点击图标弹出搜索框
  720. sousuo() {
  721. this.dialogVisible = true;
  722. },
  723. //搜索确定事件
  724. search() {
  725. let _this = this;
  726. //判断是虫害还是病害
  727. localStorage.setItem("libraryIpt", _this.input); //存下input框中的值
  728. if (localStorage.getItem("quebie") === "0") {
  729. var aaa = "insect";
  730. } else if (localStorage.getItem("quebie") === "1") {
  731. var aaa = "plant";
  732. }
  733. let postData = _this.$qs.parse({
  734. name: _this.input,
  735. ret: aaa,
  736. page: "1"
  737. });
  738. _this
  739. .$axios({
  740. method: "post",
  741. url: "bigservers/search",
  742. data: postData,
  743. headers: {
  744. "Content-Type": "application/json"
  745. }
  746. })
  747. .then(res => {
  748. if (res.data.dat.length === 0) {
  749. _this.axiosShow = false;
  750. _this.FenShow = false;
  751. } else if (res.data.dat.length !== 0) {
  752. _this.FenShow = true;
  753. _this.redata = res.data.dat;
  754. // let a = res.data.page;
  755. // let b = "5";
  756. // let d = a / b;
  757. // if (d % 1 === 0) {
  758. // _this.page = d * 10;
  759. // } else {
  760. // let g = Math.ceil(d) * 10;
  761. // console.log(g);
  762. // _this.page = g;
  763. // }
  764. localStorage.setItem("sousuoData", res.data.dat[0].req); //将搜索数据标识存在data中
  765. }
  766. })
  767. .catch(error => {
  768. console.log(error);
  769. });
  770. },
  771. //监听数字input-失去焦点
  772. animateWidthA() {
  773. // console.log("111");
  774. },
  775. //监听数字input-获取焦点
  776. animateWidth() {
  777. // console.log("222");
  778. }
  779. }
  780. };
  781. </script>
  782. <style lang='scss'>
  783. @import "../../assets/style/bus.scss";
  784. @import "../../assets/style/scss/library.scss";
  785. </style>