From 0a2d6cae514918e9c1d1422806c366d7e5723923 Mon Sep 17 00:00:00 2001
From: liuyg <376836862@qq.com>
Date: Thu, 13 Jan 2022 09:39:59 +0800
Subject: [PATCH] +活动页面加入多个地图路径以及选点

---
 src/views/hd/hd.vue |  583 +++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 357 insertions(+), 226 deletions(-)

diff --git a/src/views/hd/hd.vue b/src/views/hd/hd.vue
index 7d6e624..21e9474 100644
--- a/src/views/hd/hd.vue
+++ b/src/views/hd/hd.vue
@@ -1,271 +1,402 @@
 <template>
   <basic-container>
-    <avue-crud :option="option"
-               :table-loading="loading"
-               :data="data"
-               :page.sync="page"
-               :permission="permissionList"
-               :before-open="beforeOpen"
-               v-model="form"
-               ref="crud"
-               @row-update="rowUpdate"
-               @row-save="rowSave"
-               @row-del="rowDel"
-               @search-change="searchChange"
-               @search-reset="searchReset"
-               @selection-change="selectionChange"
-               @current-change="currentChange"
-               @size-change="sizeChange"
-               @refresh-change="refreshChange"
-               @on-load="onLoad">
+    <avue-crud
+      :option="option"
+      :table-loading="loading"
+      :data="data"
+      :page.sync="page"
+      :permission="permissionList"
+      :before-open="beforeOpen"
+      v-model="form"
+      ref="crud"
+      @row-update="rowUpdate"
+      @row-save="rowSave"
+      @row-del="rowDel"
+      @search-change="searchChange"
+      @search-reset="searchReset"
+      @selection-change="selectionChange"
+      @current-change="currentChange"
+      @size-change="sizeChange"
+      @refresh-change="refreshChange"
+      @on-load="onLoad"
+    >
       <template slot="menuLeft">
-        <el-button type="danger"
-                   size="small"
-                   icon="el-icon-delete"
-                   plain
-                   v-if="permission.hd_delete"
-                   @click="handleDelete">删 除
+        <el-button
+          type="danger"
+          size="small"
+          icon="el-icon-delete"
+          plain
+          v-if="permission.hd_delete"
+          @click="handleDelete"
+          >删 除
         </el-button>
+      </template>
+      <template slot-scope="{ type, disabled }" slot="lineForm">
+        <!-- <div class="mapClassMain" style="width: 100%; height: 400px">
+          <Map ref="modalForm" />
+        </div> -->
+        <getMapData
+          ref="getMapData"
+          id="getMapData"
+          @setMapData="setMapData"
+        ></getMapData>
       </template>
     </avue-crud>
   </basic-container>
 </template>
 
 <script>
-  import {getList, getDetail, add, update, remove} from "@/api/hd/hd";
-  import {mapGetters} from "vuex";
+import { getList, getDetail, add, update, remove } from "@/api/hd/hd";
+import { mapGetters } from "vuex";
+// import Map from "@/components/map/main.vue";
+import getMapData from "./getMapData.vue";
 
-  export default {
-    data() {
-      return {
-        form: {},
-        query: {},
-        loading: true,
-        page: {
-          pageSize: 10,
-          currentPage: 1,
-          total: 0
-        },
-        selectionList: [],
-        option: {
-          height:'auto',
-          calcHeight: 30,
-          tip: false,
-          searchShow: true,
-          searchMenuSpan: 6,
-          border: true,
-          index: true,
-          viewBtn: true,
-          align: 'center',
-          selection: true,
-          indexLabel: '序号',
-          dialogClickModal: false,
-          column: [
-            {
-              label: "活动名称",
-              prop: "hdname",
-              rules: [{
+export default {
+  components: {
+    // Map,
+    getMapData,
+  },
+  data() {
+    return {
+      form: {},
+      query: {},
+      loading: true,
+      page: {
+        pageSize: 10,
+        currentPage: 1,
+        total: 0,
+      },
+      selectionList: [],
+      option: {
+        height: "auto",
+        calcHeight: 30,
+        tip: false,
+        searchShow: true,
+        searchMenuSpan: 6,
+        border: true,
+        index: true,
+        viewBtn: true,
+        align: "center",
+        selection: true,
+        indexLabel: "序号",
+        dialogClickModal: false,
+        column: [
+          {
+            label: "活动名称",
+            prop: "hdname",
+            editDisabled: true,
+            rules: [
+              {
                 required: true,
                 message: "请输入活动名称",
-                trigger: "blur"
-              }],
-            },
-            {
-              label: "活动地点",
-              addDisplay: false,
-              hide:true,
-              editDisply:false,
-              prop: "address",
-            },
-            {
-              label: "时间",
-              prop: "time",
+                trigger: "blur",
+              },
+            ],
+          },
+          {
+            label: "活动地点",
+            addDisplay: false,
+            hide: true,
+            editDisply: false,
+            prop: "address",
+          },
+          {
+            label: "时间",
+            prop: "time",
+            type: "datetime",
+            span: 8,
+            format: "yyyy-MM-dd hh:mm:ss",
+            valueFormat: "yyyy-MM-dd hh:mm:ss",
+            mock: {
               type: "datetime",
-              span:8,
-              format:'yyyy-MM-dd hh:mm:ss',
-              valueFormat:'yyyy-MM-dd hh:mm:ss',
-              mock:{
-                type:'datetime',
-                format:'yyyy-MM-dd hh:mm:ss',
-                now:true,
-              },
+              format: "yyyy-MM-dd hh:mm:ss",
+              now: true,
             },
-            {
-              label: "图片",
-              prop: "tpurl",
-              // dataType: 'string',
-              type: "upload",
-              propsHttp: {
-                res: 'data',
-                url: 'link',
-              },
-              span: 10,
-              listType: "picture-card",
-              tip: "只能上传jpg/png文件,且不超过500kb",
+          },
+          {
+            label: "图片",
+            prop: "tpurl",
+            // dataType: 'string',
+            type: "upload",
+            propsHttp: {
+              res: "data",
+              url: "link",
+            },
+            span: 24,
+            listType: "picture-card",
+            tip: "只能上传jpg/png文件,且不超过500kb",
+            action: "/api/blade-resource/oss/endpoint/put-file",
+          },
+          {
+            label: "选择路径和标点",
+            labelWidth: "0",
+            prop: "line",
+            className: "mapClass",
+            hide: true,
+            display: true,
+            span: 24,
+            formslot: true,
+            addDisplay: true,
+          },
+          {
+            label: "介绍",
+            prop: "context",
+            component: "AvueUeditor",
+            options: {
               action: "/api/blade-resource/oss/endpoint/put-file",
-            },
-            {
-              label: "介绍",
-              prop: "context",
-              component: 'AvueUeditor',
-              options: {
-                action: '/api/blade-resource/oss/endpoint/put-file',
-                props: {
-                  res: "data",
-                  url: "link",
-                }
+              props: {
+                res: "data",
+                url: "link",
               },
-              minRows: 5,
-              span: 24,
             },
-            {
-              label: "路线",
-              hide:true,
-              prop: "lx",
-              editDisply:false,
-              addDisplay: false,
-            },
-          ]
-        },
-        data: []
+            minRows: 5,
+            span: 24,
+          },
+          // {
+          //   label: "路线",
+          //   hide: true,
+          //   prop: "lx",
+          //   editDisply: false,
+          //   addDisplay: false,
+          // },
+        ],
+      },
+      data: [],
+      LineData: [],
+      PointData: [],
+    };
+  },
+  // watch: {
+  // rotesData() {
+  //   console.log(this.rotesData);
+  // },
+  // pointData() {
+  //   console.log(this.pointData);
+  // },
+  // },
+  computed: {
+    ...mapGetters(["permission"]),
+    permissionList() {
+      return {
+        addBtn: this.vaildData(this.permission.hd_add, false),
+        viewBtn: this.vaildData(this.permission.hd_view, false),
+        delBtn: this.vaildData(this.permission.hd_delete, false),
+        editBtn: this.vaildData(this.permission.hd_edit, false),
       };
     },
-    computed: {
-      ...mapGetters(["permission"]),
-      permissionList() {
-        return {
-          addBtn: this.vaildData(this.permission.hd_add, false),
-          viewBtn: this.vaildData(this.permission.hd_view, false),
-          delBtn: this.vaildData(this.permission.hd_delete, false),
-          editBtn: this.vaildData(this.permission.hd_edit, false)
-        };
-      },
-      ids() {
-        let ids = [];
-        this.selectionList.forEach(ele => {
-          ids.push(ele.id);
-        });
-        return ids.join(",");
-      }
+    ids() {
+      let ids = [];
+      this.selectionList.forEach((ele) => {
+        ids.push(ele.id);
+      });
+      return ids.join(",");
     },
-    methods: {
-      rowSave(row, done, loading) {
-        var d = [];
-        for (var k in row.tpurl) {
-          d.push(row.tpurl[k].value);
-        }
-        row.tpurl = d.join(",");
-        add(row).then(() => {
+  },
+  methods: {
+    setMapData(val) {
+      this.LineData = val[0];
+      this.PointData = val[1];
+    },
+    rowSave(row, done, loading) {
+      var d = [];
+      for (var k in row.tpurl) {
+        d.push(row.tpurl[k].value);
+      }
+      row.tpurl = d.join(",");
+      let outMapData = this.$refs.getMapData.myRulesUse();
+      if (!outMapData) {
+        loading();
+        return;
+      }
+      row["lxname"] = outMapData[0][0];
+      row["lx"] = outMapData[0][1];
+      row["addressname"] = outMapData[1][0];
+      row["address"] = outMapData[1][1];
+      add(row).then(
+        () => {
           this.onLoad(this.page);
           this.$message({
             type: "success",
-            message: "操作成功!"
+            message: "操作成功!",
           });
           done();
-        }, error => {
+        },
+        (error) => {
           loading();
           window.console.log(error);
-        });
-      },
-      rowUpdate(row, index, done, loading) {
-        update(row).then(() => {
+        }
+      );
+    },
+    rowUpdate(row, index, done, loading) {
+      let outMapData = this.$refs.getMapData.myRulesUse();
+      if (!outMapData) {
+        loading();
+        return;
+      }
+      row["lxname"] = outMapData[0][0];
+      row["lx"] = outMapData[0][1];
+      row["addressname"] = outMapData[1][0];
+      row["address"] = outMapData[1][1];
+      update(row).then(
+        () => {
           this.onLoad(this.page);
           this.$message({
             type: "success",
-            message: "操作成功!"
+            message: "操作成功!",
           });
           done();
-        }, error => {
+        },
+        (error) => {
           loading();
           console.log(error);
+        }
+      );
+    },
+    rowDel(row) {
+      this.$confirm("确定将选择数据删除?", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning",
+      })
+        .then(() => {
+          return remove(row.id);
+        })
+        .then(() => {
+          this.onLoad(this.page);
+          this.$message({
+            type: "success",
+            message: "操作成功!",
+          });
         });
-      },
-      rowDel(row) {
-        this.$confirm("确定将选择数据删除?", {
-          confirmButtonText: "确定",
-          cancelButtonText: "取消",
-          type: "warning"
+    },
+    handleDelete() {
+      if (this.selectionList.length === 0) {
+        this.$message.warning("请选择至少一条数据");
+        return;
+      }
+      this.$confirm("确定将选择数据删除?", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning",
+      })
+        .then(() => {
+          return remove(this.ids);
         })
-          .then(() => {
-            return remove(row.id);
-          })
-          .then(() => {
-            this.onLoad(this.page);
-            this.$message({
-              type: "success",
-              message: "操作成功!"
-            });
+        .then(() => {
+          this.onLoad(this.page);
+          this.$message({
+            type: "success",
+            message: "操作成功!",
           });
-      },
-      handleDelete() {
-        if (this.selectionList.length === 0) {
-          this.$message.warning("请选择至少一条数据");
-          return;
+          this.$refs.crud.toggleSelection();
+        });
+    },
+    checkDom(name, fn) {
+      //  声明定时器
+      let that = this;
+      var timer = null;
+      //  检查dom是否执行完成
+      function checkDom() {
+        let dom = that.$refs[name];
+        if (dom) {
+          //  执行dom加载完成后的操作
+          //  清除定时器
+          if (!timer) {
+            clearTimeout(timer);
+          }
+          if (fn) {
+            //回调函数
+            fn(dom);
+            return;
+          } else {
+            return dom;
+          }
+        } else {
+          //  自我调用
+          timer = setTimeout(checkDom, 100);
         }
-        this.$confirm("确定将选择数据删除?", {
-          confirmButtonText: "确定",
-          cancelButtonText: "取消",
-          type: "warning"
-        })
-          .then(() => {
-            return remove(this.ids);
-          })
-          .then(() => {
-            this.onLoad(this.page);
-            this.$message({
-              type: "success",
-              message: "操作成功!"
-            });
-            this.$refs.crud.toggleSelection();
-          });
-      },
-      beforeOpen(done, type) {
-        if (["edit", "view"].includes(type)) {
-          getDetail(this.form.id).then(res => {
-            this.form = res.data.data;
-          });
-        }
-        done();
-      },
-      searchReset() {
-        this.query = {};
-        this.onLoad(this.page);
-      },
-      searchChange(params, done) {
-        this.query = params;
-        this.page.currentPage = 1;
-        this.onLoad(this.page, params);
-        done();
-      },
-      selectionChange(list) {
-        this.selectionList = list;
-      },
-      selectionClear() {
-        this.selectionList = [];
-        this.$refs.crud.toggleSelection();
-      },
-      currentChange(currentPage){
-        this.page.currentPage = currentPage;
-      },
-      sizeChange(pageSize){
-        this.page.pageSize = pageSize;
-      },
-      refreshChange() {
-        this.onLoad(this.page, this.query);
-      },
-      onLoad(page, params = {}) {
-        this.loading = true;
-        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
-          const data = res.data.data;
-          this.page.total = data.total;
-          this.data = data.records;
-          this.loading = false;
-          this.selectionClear();
+      }
+      //  首次执行
+      checkDom();
+    },
+    beforeOpen(done, type) {
+      let that = this;
+      if (["edit", "view"].includes(type)) {
+        getDetail(this.form.id).then((res) => {
+          this.form = res.data.data;
+        });
+        //控制按钮不可编辑
+        this.checkDom("getMapData", (dom) => {
+          // dom.init(val, num, value);
+          dom[type + "Init"]([
+            [that.form.lxname, that.form.lx],
+            [that.form.addressname, that.form.address],
+          ]);
         });
       }
-    }
-  };
+
+      done();
+    },
+    searchReset() {
+      this.query = {};
+      this.onLoad(this.page);
+    },
+    searchChange(params, done) {
+      this.query = params;
+      this.page.currentPage = 1;
+      this.onLoad(this.page, params);
+      done();
+    },
+    selectionChange(list) {
+      this.selectionList = list;
+    },
+    selectionClear() {
+      this.selectionList = [];
+      this.$refs.crud.toggleSelection();
+    },
+    currentChange(currentPage) {
+      this.page.currentPage = currentPage;
+    },
+    sizeChange(pageSize) {
+      this.page.pageSize = pageSize;
+    },
+    refreshChange() {
+      this.onLoad(this.page, this.query);
+    },
+    onLoad(page, params = {}) {
+      this.loading = true;
+      getList(
+        page.currentPage,
+        page.pageSize,
+        Object.assign(params, this.query)
+      ).then((res) => {
+        const data = res.data.data;
+        this.page.total = data.total;
+        this.data = data.records;
+        this.loading = false;
+        this.selectionClear();
+      });
+    },
+  },
+};
 </script>
 
 <style>
+.mapClass {
+  margin-left: 88px;
+}
+.mapClass div label {
+  display: none;
+}
+
+.mapClassMain {
+  /* padding-left: 25px !important; */
+}
+
+#getMapData {
+  width: calc(100% + 90px);
+  position: relative;
+  left: -90px;
+  height: auto;
+}
 </style>

--
Gitblit v1.9.3