insectName.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <template>
  2. <div class="insectName-box">
  3. <el-container>
  4. <!-- 页头 -->
  5. <el-header>
  6. <el-page-header title @back="goBack" content="昆虫名称设置"></el-page-header>
  7. <!-- 添加框 -->
  8. <el-button type="text" @click="dialogFormVisible = true">
  9. <img src="../../assets/imageOne/23.png" alt class="insectName-img" />
  10. </el-button>
  11. <el-dialog title="添加昆虫名称" :visible.sync="dialogFormVisible" :before-close="handleCloseA">
  12. <el-form :model="form">
  13. <el-form-item label :label-width="formLabelWidth">
  14. <el-input v-model.trim="form.newName" autocomplete="off"></el-input>
  15. </el-form-item>
  16. </el-form>
  17. <div slot="footer" class="dialog-footer">
  18. <el-button @click="dialogFormVisible = false,cancel()">取 消</el-button>
  19. <el-button type="primary" @click="dialogFormVisible = false,add()">确 定</el-button>
  20. </div>
  21. </el-dialog>
  22. <!-- 添加框 -->
  23. <!-- 编辑框 -->
  24. <el-dialog title="编辑昆虫名称" :visible.sync="dialogFormVisible1" :before-close="handleCloseA">
  25. <el-form :model="form">
  26. <el-form-item label :label-width="formLabelWidth">
  27. <el-input
  28. v-model.trim="form.newName"
  29. ref="input1"
  30. autocomplete="off"
  31. :placeholder="inputText"
  32. ></el-input>
  33. </el-form-item>
  34. </el-form>
  35. <div slot="footer" class="dialog-footer">
  36. <el-button @click="dialogFormVisible1 = false,cancel()">取 消</el-button>
  37. <el-button type="primary" @click="dialogFormVisible1 = false,bianjijian()">确 定</el-button>
  38. </div>
  39. </el-dialog>
  40. <!-- 编辑框 -->
  41. <!-- 删除框 -->
  42. <el-dialog title="提示" :visible.sync="dialogVisibleshan" :before-close="handleCloseshanchu">
  43. <span>确定删除此条信息吗?</span>
  44. <span slot="footer" class="dialog-footer">
  45. <el-button @click="dialogVisibleshan = false">取 消</el-button>
  46. <el-button type="primary" @click="dialogVisibleshan = false,shanchuque()">确 定</el-button>
  47. </span>
  48. </el-dialog>
  49. <!-- 删除框 -->
  50. </el-header>
  51. <!-- 页面主内容 -->
  52. <el-main
  53. :style="'height:' + fullHeight + 'px'"
  54. v-loading="loading"
  55. element-loading-text="拼命加载中"
  56. element-loading-spinner="el-icon-loading"
  57. element-loading-background="rgba(0, 0, 0, 0.8)"
  58. style="width: 100%"
  59. >
  60. <ul class="insectName-ul">
  61. <li
  62. class="insectName-li"
  63. v-if="item.insect_name !== null && item.insect_name !== ''"
  64. v-for="(item,index) in this.redata"
  65. :key="index"
  66. >
  67. <img src="../../assets/imageOne/22.png" alt class="insectName-li-img" />
  68. <div class="insectName-li-div">
  69. <div
  70. class="insectName-li-text"
  71. @click="dianji($event,index,item.id,item.insect_name)"
  72. >{{item.insect_name}}</div>
  73. </div>
  74. </li>
  75. </ul>
  76. <!-- 编辑删除添加框 -->
  77. <el-dialog title="提示" :visible.sync="dialogVisible" :before-close="handleClose">
  78. <div class="tanchuk1" @click="tianjia()">添加</div>
  79. <div class="tanchuk1" @click="dialogFormVisible1 = true,bianji()">编辑</div>
  80. <div class="tanchuk1" @click="dialogVisibleshan = true,shanchu()">删除</div>
  81. <span slot="footer" class="dialog-footer">
  82. <el-button @click="dialogVisible = false" class="xuxiaobtn">取 消</el-button>
  83. </span>
  84. </el-dialog>
  85. <!-- 编辑删除添加框 -->
  86. </el-main>
  87. </el-container>
  88. </div>
  89. </template>
  90. <script>
  91. export default {
  92. name: "insectName",
  93. data() {
  94. return {
  95. form: {
  96. newName: "" //添加中input的双向绑定
  97. },
  98. dialogVisible: false,
  99. dialogTableVisible: false,
  100. dialogFormVisible: false,
  101. dialogVisibleshan: false, //删除
  102. formLabelWidth: "120px",
  103. dialogTableVisible: false,
  104. dialogFormVisible1: false, //编辑
  105. inputText: "",
  106. current: "", //点击list的下标
  107. fullHeight: document.documentElement.clientHeight,
  108. redata: {}, //后端获取的数据
  109. loading: true
  110. };
  111. },
  112. watch: {
  113. fullHeight(val) {
  114. //监控浏览器高度变化
  115. if (!this.timer) {
  116. this.fullHeight = val;
  117. this.timer = true;
  118. let that = this;
  119. setTimeout(function() {
  120. //防止过度调用监测事件,导致卡顿
  121. that.timer = false;
  122. }, 400);
  123. }
  124. }
  125. },
  126. mounted() {
  127. this.get_boderHeight();
  128. },
  129. created() {
  130. let _this = this;
  131. //进入页面就获取后端数据
  132. let postData = _this.$qs.parse({
  133. insect_type: localStorage.getItem('kunchongInsect'), //昆虫种类
  134. })
  135. _this
  136. .$axios({
  137. method: "post",
  138. url: "bigservers/check_insect_leve",
  139. data: postData,
  140. headers: {
  141. "Content-Type": "application/json"
  142. }
  143. })
  144. .then(res => {
  145. _this.redata = res.data;
  146. _this.loading = false;
  147. })
  148. .catch(error => {
  149. alert("失败");
  150. console.log(error);
  151. });
  152. },
  153. methods: {
  154. //动态获取浏览器高度
  155. get_boderHeight() {
  156. const that = this;
  157. window.onresize = () => {
  158. return (() => {
  159. window.fullHeight = document.documentElement.clientHeight;
  160. that.fullHeight = window.fullHeight;
  161. })();
  162. };
  163. },
  164. //点击返回系统设置页面
  165. goBack() {
  166. let _this = this;
  167. localStorage.removeItem("kunNames");
  168. localStorage.removeItem("kunNameID");
  169. _this.$router.push("/system");
  170. location.reload();
  171. },
  172. //编辑框
  173. handleClose(done) {
  174. let _this = this;
  175. _this.dialogVisible = false;
  176. },
  177. //删除框
  178. handleCloseshanchu(done) {
  179. let _this = this;
  180. _this.dialogVisibleshan = false;
  181. },
  182. add() {
  183. let _this = this;
  184. let postData = _this.$qs.parse({
  185. insect_name: _this.form.newName,
  186. insect_type: localStorage.getItem('kunchongInsect'), //昆虫种类
  187. });
  188. if (_this.form.newName !== "") {
  189. _this
  190. .$axios({
  191. method: "post",
  192. url: "bigservers/addr_insect_type",
  193. data: postData,
  194. headers: {
  195. "Content-Type": "application/json"
  196. }
  197. })
  198. .then(res => {
  199. if (res.data !== 0) {
  200. this.$message({
  201. type: "success",
  202. message: "添加成功!"
  203. });
  204. const timer = setInterval(() => {
  205. location.reload();
  206. }, 1000);
  207. } else {
  208. this.$message({
  209. type: "warning",
  210. message: "数据已存在!"
  211. });
  212. }
  213. _this.cancel();
  214. })
  215. .catch(error => {
  216. this.$message({
  217. showClose: true,
  218. message: "失败",
  219. type: "error"
  220. });
  221. });
  222. } else {
  223. this.$message({
  224. type: "warning",
  225. message: "不能为空!"
  226. });
  227. }
  228. },
  229. //点击list跳出弹框
  230. dianji(e, index, id, insect_name) {
  231. let _this = this;
  232. _this.current = index;
  233. if (e.target.className === "insectName-li-text") {
  234. let el = e.currentTarget;
  235. let data = el.innerHTML;
  236. let dataID = id;
  237. (_this.dialogVisible = true), (_this.inputText = data);
  238. let dataNames = insect_name;
  239. localStorage.setItem("kunNames", dataNames);
  240. localStorage.setItem("kunNameID", dataID);
  241. }
  242. },
  243. //点击小弹框中的添加
  244. tianjia() {
  245. let _this = this;
  246. _this.dialogFormVisible = true;
  247. _this.dialogVisible = false;
  248. },
  249. //点击小弹框中的编辑
  250. bianji() {
  251. let _this = this;
  252. _this.dialogVisible = false;
  253. },
  254. //点击小弹框中的删除
  255. shanchu() {
  256. let _this = this;
  257. _this.dialogVisible = false;
  258. },
  259. //删除确定事件
  260. shanchuque() {
  261. let _this = this;
  262. let postData = _this.$qs.parse({
  263. insect_type: localStorage.getItem('kunchongInsect'), //昆虫种类
  264. id: localStorage.kunNameID,
  265. insect_name: localStorage.kunNames, //昆虫名称
  266. ret: "del"
  267. });
  268. _this
  269. .$axios({
  270. method: "post",
  271. url: "bigservers/modify_insect_leve",
  272. data: postData,
  273. headers: {
  274. "Content-Type": "application/json"
  275. }
  276. })
  277. .then(res => {
  278. this.$message({
  279. type: "success",
  280. message: "删除成功!"
  281. });
  282. const timer = setInterval(() => {
  283. location.reload();
  284. }, 1000);
  285. })
  286. .catch(error => {
  287. this.$message({
  288. type: "error",
  289. message: "删除失败!"
  290. });
  291. });
  292. },
  293. //编辑确定事件
  294. bianjijian() {
  295. let _this = this;
  296. let postData = _this.$qs.parse({
  297. insect_type: localStorage.getItem('kunchongInsect'), //昆虫种类
  298. id: localStorage.kunNameID,
  299. insect_name: _this.form.newName, //用户编辑时填写的数据
  300. ret: "edit"
  301. });
  302. if (_this.form.newName) {
  303. _this
  304. .$axios({
  305. method: "post",
  306. url: "bigservers/modify_insect_leve",
  307. data: postData,
  308. headers: {
  309. "Content-Type": "application/json"
  310. }
  311. })
  312. .then(res => {
  313. if (res.data !== 0) {
  314. this.$message({
  315. type: "success",
  316. message: "编辑成功!"
  317. });
  318. const timer = setInterval(() => {
  319. location.reload();
  320. }, 1000);
  321. } else {
  322. this.$message({
  323. type: "warning",
  324. message: "数据已存在!"
  325. });
  326. }
  327. _this.cancel();
  328. })
  329. .catch(error => {
  330. this.$message({
  331. type: "error",
  332. message: "失败!"
  333. });
  334. });
  335. } else {
  336. this.$message({
  337. type: "warning",
  338. message: "不能为空!"
  339. });
  340. }
  341. },
  342. //取消清空input框中数据
  343. cancel() {
  344. let _this = this;
  345. _this.form.newName = "";
  346. },
  347. //弹出框右上角关闭按钮回调
  348. handleCloseA() {
  349. let _this = this;
  350. _this.dialogFormVisible1 = false;
  351. _this.dialogFormVisible = false;
  352. _this.cancel();
  353. }
  354. }
  355. };
  356. </script>
  357. <style lang="scss">
  358. @import "../../assets/style/bus.scss";
  359. @import "../../assets/style/scss/insectName.scss";
  360. </style>