shuishen
2022-07-21 03df59a72de4354fcc731675c53dd2805c2ec8b1
src/views/hd/hd.vue
@@ -32,22 +32,18 @@
        </el-button>
      </template> -->
      <template slot-scope="{ type, disabled }" slot="lineForm">
        <getMapDataInThere
          ref="getMapData"
          id="getMapData"
          @setMapData="setMapData"
        ></getMapDataInThere>
                <getMapDataInThere ref="getMapData" id="getMapData" @setMapData="setMapData"></getMapDataInThere>
      </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";
import getMapDataInThere from "./getMapDataInThere.vue";
import getMapData from "./getMapData.vue"
import getMapDataInThere from "./getMapDataInThere.vue"
export default {
  components: {
@@ -188,7 +184,7 @@
      data: [],
      LineData: [],
      PointData: [],
    };
        }
  },
  // watch: {
  // rotesData() {
@@ -206,81 +202,81 @@
        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 = [];
            let ids = []
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
                ids.push(ele.id)
            })
            return ids.join(",")
    },
  },
  methods: {
    setMapData(val) {
      this.LineData = val[0];
      this.PointData = val[1];
            this.LineData = val[0]
            this.PointData = val[1]
    },
    rowSave(row, done, loading) {
      var d = [];
            var d = []
      for (var k in row.tpurl) {
        d.push(row.tpurl[k].value);
                d.push(row.tpurl[k].value)
      }
      row.tpurl = d.join(",");
      let outMapData = this.$refs.getMapData.myRulesUse();
            row.tpurl = d.join(",")
            let outMapData = this.$refs.getMapData.myRulesUse()
      if (!outMapData) {
        loading();
        return;
                loading()
                return
      }
      row["lxname"] = outMapData[0][0];
      row["lx"] = outMapData[0][1];
      row["addressname"] = outMapData[1][0];
      row["address"] = outMapData[1][1];
            row["lxname"] = outMapData[0][0]
            row["lx"] = outMapData[0][1]
            row["addressname"] = outMapData[1][0]
            row["address"] = outMapData[1][1]
      // console.log(row);
      // loading();
      // return;
      add(row).then(
        () => {
          this.onLoad(this.page);
                    this.onLoad(this.page)
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
                    })
                    done()
        },
        (error) => {
          loading();
          window.console.log(error);
                    loading()
                    window.console.log(error)
        }
      );
            )
    },
    rowUpdate(row, index, done, loading) {
      let outMapData = this.$refs.getMapData.myRulesUse();
            let outMapData = this.$refs.getMapData.myRulesUse()
      if (!outMapData) {
        loading();
        return;
                loading()
                return
      }
      row["lxname"] = outMapData[0][0];
      row["lx"] = outMapData[0][1];
      row["addressname"] = outMapData[1][0];
      row["address"] = outMapData[1][1];
            row["lxname"] = outMapData[0][0]
            row["lx"] = outMapData[0][1]
            row["addressname"] = outMapData[1][0]
            row["address"] = outMapData[1][1]
      // console.log(row);
      // loading();
      // return;
      update(row).then(
        () => {
          this.onLoad(this.page);
                    this.onLoad(this.page)
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
                    })
                    done()
        },
        (error) => {
          loading();
          console.log(error);
                    loading()
                    console.log(error)
        }
      );
            )
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
@@ -289,20 +285,20 @@
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
                    return remove(row.id)
        })
        .then(() => {
          this.onLoad(this.page);
                    this.onLoad(this.page)
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
                    })
                })
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
                this.$message.warning("请选择至少一条数据")
                return
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
@@ -310,104 +306,104 @@
        type: "warning",
      })
        .then(() => {
          return remove(this.ids);
                    return remove(this.ids)
        })
        .then(() => {
          this.onLoad(this.page);
                    this.onLoad(this.page)
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs.crud.toggleSelection();
        });
                    })
                    this.$refs.crud.toggleSelection()
                })
    },
    checkDom(name, fn) {
      //  声明定时器
      let that = this;
      var timer = null;
            let that = this
            var timer = null
      //  检查dom是否执行完成
      function checkDom() {
        let dom = that.$refs[name];
                let dom = that.$refs[name]
        if (dom) {
          //  执行dom加载完成后的操作
          //  清除定时器
          if (!timer) {
            clearTimeout(timer);
                        clearTimeout(timer)
          }
          if (fn) {
            //回调函数
            fn(dom);
            return;
                        fn(dom)
                        return
          } else {
            return dom;
                        return dom
          }
        } else {
          //  自我调用
          timer = setTimeout(checkDom, 100);
                    timer = setTimeout(checkDom, 100)
        }
      }
      //  首次执行
      checkDom();
            checkDom()
    },
    beforeOpen(done, type) {
      let that = this;
            let that = this
      if (["edit", "view"].includes(type)) {
        getDetail(this.form.id).then((res) => {
          this.form = res.data.data;
        });
                    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();
            done()
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
            this.query = {}
            this.onLoad(this.page)
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
            this.query = params
            this.page.currentPage = 1
            this.onLoad(this.page, params)
            done()
    },
    selectionChange(list) {
      this.selectionList = list;
            this.selectionList = list
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
            this.selectionList = []
            this.$refs.crud.toggleSelection()
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
            this.page.currentPage = currentPage
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
            this.page.pageSize = pageSize
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
            this.onLoad(this.page, this.query)
    },
    onLoad(page, params = {}) {
      this.loading = true;
            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();
      });
                const data = res.data.data
                this.page.total = data.total
                this.data = data.records
                this.loading = false
                this.selectionClear()
            })
    },
  },
};