<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="98px">
<!--      <el-form-item label="部门id" prop="deptId">-->
<!--        <el-input-->
<!--          v-model="queryParams.deptId"-->
<!--          placeholder="请输入部门id"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

        <el-form-item class="treeselectForm treeselectForm2 treeselectFormz" label="组织架构" prop="orgIds" style="width: auto">
          <tree @treeselectFn="treeselectFn" :treeval="queryParams.orgIds" ></tree>
        </el-form-item>
<!--      <el-form-item label="门店id" prop="storeId">-->
<!--        <el-input-->
<!--          v-model="queryParams.storeId"-->
<!--          placeholder="请输入门店id"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="门店编码" prop="storeCode">
        <el-input
          v-model="queryParams.storeCode"
          placeholder="请输入门店编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="门店名称" prop="storeName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入门店名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="重置用户id" prop="userId">-->
<!--        <el-input-->
<!--          v-model="queryParams.userId"-->
<!--          placeholder="请输入重置用户id"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="重置用户name" prop="userName">-->
<!--        <el-input-->
<!--          v-model="queryParams.userName"-->
<!--          placeholder="请输入重置用户name"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="用户名称" prop="userNickName">
        <el-input
          v-model="queryParams.userNickName"
          placeholder="请输入用户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="重置用户工号" prop="workCode">-->
<!--        <el-input-->
<!--          v-model="queryParams.workCode"-->
<!--          placeholder="请输入重置用户工号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="重置时间" prop="refreshTime">-->
<!--        <el-date-picker clearable size="small"-->
<!--          v-model="queryParams.refreshTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="选择重置时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="重置端：M移动端、P管理后台" prop="refreshFrom">-->
<!--        <el-input-->
<!--          v-model="queryParams.refreshFrom"-->
<!--          placeholder="请输入重置端：M移动端、P管理后台"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="重置前经度" prop="beforeLon">-->
<!--        <el-input-->
<!--          v-model="queryParams.beforeLon"-->
<!--          placeholder="请输入重置前经度"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="重置前纬度" prop="beforeLat">-->
<!--        <el-input-->
<!--          v-model="queryParams.beforeLat"-->
<!--          placeholder="请输入重置前纬度"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="重置后经度" prop="lon">-->
<!--        <el-input-->
<!--          v-model="queryParams.lon"-->
<!--          placeholder="请输入重置后经度"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="重置后纬度" prop="lat">-->
<!--        <el-input-->
<!--          v-model="queryParams.lat"-->
<!--          placeholder="请输入重置后纬度"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sfa:storePositionRefresh:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="storePositionRefreshList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="门店编码" align="center" prop="storeCode" width="140"  :show-overflow-tooltip="true" />
      <el-table-column label="门店名称" align="center" prop="storeName" width="180"  :show-overflow-tooltip="true" />
      <el-table-column label="大区" align="center" prop="regionName" width="180"  :show-overflow-tooltip="true" />
      <el-table-column label="公司" align="center" prop="companyName" width="180"  :show-overflow-tooltip="true" />
      <el-table-column label="部门" align="center" prop="deptName" width="180"  :show-overflow-tooltip="true" />
      <el-table-column label="用户名称" align="center" prop="userNickName" width="180"  :show-overflow-tooltip="true" />
      <el-table-column label="重置用户工号" align="center" prop="workCode" width="180"  :show-overflow-tooltip="true" />
      <el-table-column label="重置时间" align="center" prop="refreshTime" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refreshTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="来源" align="center" prop="refreshFrom" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.refreshFrom=='M'">移动端</span>
          <span v-else>管理后台</span>
        </template>
      </el-table-column>
      <el-table-column label="重置前经度" align="center" prop="beforeLon" width="180"/>
      <el-table-column label="重置前纬度" align="center" prop="beforeLat" width="180"/>
      <el-table-column label="重置后经度" align="center" prop="lon" width="180"/>
      <el-table-column label="重置后纬度" align="center" prop="lat" width="180"/>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改门店经纬度重置记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门id" />
        </el-form-item>
        <el-form-item label="门店id" prop="storeId">
          <el-input v-model="form.storeId" placeholder="请输入门店id" />
        </el-form-item>
        <el-form-item label="门店code" prop="storeCode">
          <el-input v-model="form.storeCode" placeholder="请输入门店code" />
        </el-form-item>
        <el-form-item label="门店名称" prop="storeName">
          <el-input v-model="form.storeName" placeholder="请输入门店名称" />
        </el-form-item>
        <el-form-item label="重置用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入重置用户id" />
        </el-form-item>
        <el-form-item label="重置用户name" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入重置用户name" />
        </el-form-item>
        <el-form-item label="用户名称" prop="userNickName">
          <el-input v-model="form.userNickName" placeholder="请输入用户名称" />
        </el-form-item>
        <el-form-item label="重置用户工号" prop="workCode">
          <el-input v-model="form.workCode" placeholder="请输入重置用户工号" />
        </el-form-item>
        <el-form-item label="重置时间" prop="refreshTime">
          <el-date-picker clearable size="small"
            v-model="form.refreshTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择重置时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="重置端：M移动端、P管理后台" prop="refreshFrom">
          <el-input v-model="form.refreshFrom" placeholder="请输入重置端：M移动端、P管理后台" />
        </el-form-item>
        <el-form-item label="重置前经度" prop="beforeLon">
          <el-input v-model="form.beforeLon" placeholder="请输入重置前经度" />
        </el-form-item>
        <el-form-item label="重置前纬度" prop="beforeLat">
          <el-input v-model="form.beforeLat" placeholder="请输入重置前纬度" />
        </el-form-item>
        <el-form-item label="重置后经度" prop="lon">
          <el-input v-model="form.lon" placeholder="请输入重置后经度" />
        </el-form-item>
        <el-form-item label="重置后纬度" prop="lat">
          <el-input v-model="form.lat" placeholder="请输入重置后纬度" />
        </el-form-item>
        <el-form-item label="删除标记" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标记" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStorePositionRefresh, getStorePositionRefresh, delStorePositionRefresh, addStorePositionRefresh, updateStorePositionRefresh } from "@/api/sfa/storePositionRefresh";
import tree from "@/views/components/sfa/treeselect";
export default {
  name: "StorePositionRefresh",
  components: { tree },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 门店经纬度重置记录表格数据
      storePositionRefreshList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgIds: null,
        storeId: null,
        storeCode: null,
        storeName: null,
        userId: null,
        userName: null,
        userNickName: null,
        workCode: null,
        refreshTime: null,
        refreshFrom: null,
        beforeLon: null,
        beforeLat: null,
        lon: null,
        lat: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    treeselectFn(val){
      this.queryParams.orgIds = val;
      this.$forceUpdate();
      // this.getChainList();
    },
    /** 查询门店经纬度重置记录列表 */
    getList() {
      this.loading = true;
      listStorePositionRefresh(this.queryParams).then(response => {
        this.storePositionRefreshList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        refreshId: null,
        deptId: null,
        storeId: null,
        storeCode: null,
        storeName: null,
        userId: null,
        userName: null,
        userNickName: null,
        workCode: null,
        refreshTime: null,
        refreshFrom: null,
        beforeLon: null,
        beforeLat: null,
        lon: null,
        lat: null,
        delFlag: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.refreshId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加门店经纬度重置记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const refreshId = row.refreshId || this.ids
      getStorePositionRefresh(refreshId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改门店经纬度重置记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.refreshId != null) {
            updateStorePositionRefresh(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStorePositionRefresh(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const refreshIds = row.refreshId || this.ids;
      this.$modal.confirm('是否确认删除门店经纬度重置记录编号为"' + refreshIds + '"的数据项？').then(function() {
        return delStorePositionRefresh(refreshIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sfa/storePositionRefresh/export', {
        ...this.queryParams
      }, `storePositionRefresh_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
