<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-col :span="24" class="one_1"> 投诉信息查询 </el-col>
          <el-col :span="24" class="one_2">
            <el-form ref="searchFrom" :model="searchFrom" label-width="125px">
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="管辖单位名称">
                    <el-select v-model="searchFrom.tube_company" clearable placeholder="请选择">
                      <el-option v-for="(item, index) in tube_companyList" :key="index" :label="item.name" :value="item.name"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="被投诉单位类型">
                    <el-select v-model="searchFrom.cover_complaint_comtype" clearable placeholder="请选择">
                      <el-option v-for="(item, index) in cover_complaint_comtypeList" :key="index" :label="item" :value="item"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="被投诉单位名称">
                    <el-input v-model="searchFrom.cover_complaint_com"></el-input>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="被投诉保安员姓名">
                    <el-input v-model="searchFrom.cover_complaint_comname"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="投诉日期">
                    <el-date-picker
                      v-model="searchFrom['start@complaint_date']"
                      placeholder="请选择"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      type="date"
                      style="width: 100%"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="至">
                    <el-date-picker
                      v-model="searchFrom['end@complaint_date']"
                      placeholder="请选择"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      type="date"
                      style="width: 100%"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="处理状态">
                    <el-select v-model="searchFrom.handle_status" clearable placeholder="请选择">
                      <el-option label="处理" value="处理"></el-option>
                      <el-option label="未处理" value="未处理"></el-option>
                      <el-option label="注销" value="注销"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="16" class="btn">
                  <el-button type="primary" size="mini" @click="search()">查询</el-button>
                  <el-button type="primary" size="mini" @click="toAdd()">添加</el-button>
                </el-col>
              </el-col>
            </el-form>
          </el-col>
        </el-col>
        <el-col :span="24" class="two">
          <data-table @query="search" :fields="fields" :opera="opera" :data="list" :total="total" @edit="toEdit" @handle="handle" @cancel="cancel">
          </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const { cover_complaint_comtype } = require('@common/src/layout/deploy/dict');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: complaints_info } = createNamespacedHelpers('complaints_info');
const { mapActions: police_department } = createNamespacedHelpers('police_department');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      // 查询
      searchFrom: {},
      // 列表
      fields: [
        { label: '投诉人姓名', model: 'complaint_personal' },
        { label: '投诉人联系电话', model: 'complaint_phone' },
        { label: '投诉日期', model: 'complaint_date' },
        { label: '被投诉单位名称', model: 'cover_complaint_com' },
        { label: '被投诉单位类型', model: 'cover_complaint_comtype' },
        { label: '被投诉保安员姓名', model: 'cover_complaint_comname' },
        { label: '受理单位名称', model: 'accept_company' },
        { label: '投诉状态', model: 'handle_status' },
      ],
      opera: [
        { label: '维护', method: 'edit' },
        { label: '已处理', method: 'handle' },
        { label: '注销', method: 'cancel', type: 'danger' },
      ],
      list: [],
      total: 0,
      tube_companyList: [],
      cover_complaint_comtypeList: cover_complaint_comtype,
    };
  },
  created() {
    this.searchOther();
    this.search();
  },
  methods: {
    ...complaints_info(['query', 'update']),
    ...police_department({ deptQuery: 'query' }),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const condition = _.cloneDeep(this.searchFrom);
      let res = await this.query({ skip, limit, ...condition, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 添加
    toAdd() {
      this.$router.push({ path: '/adminPolice/complaint/tsxxcx/add' });
    },
    // 维护
    toEdit({ data }) {
      this.$router.push({ path: '/adminPolice/complaint/tsxxcx/add', query: { id: data.id } });
    },
    // 已处理
    async handle({ data }) {
      this.$confirm(`您确认提交已处理吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          data.handle_status = '已处理';
          let res = await this.update(data);
          if (this.$checkRes(res)) {
            this.$message({ type: `success`, message: `操作成功` });
            this.back();
          } else {
            this.$message({ type: `success`, message: `${res.errmsg}` });
          }
        })
        .catch(() => {});
    },
    // 注销
    async cancel({ data }) {
      this.$confirm(`您确认提交注销吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          data.handle_status = '注销';
          let res = await this.update(data);
          if (this.$checkRes(res)) {
            this.$message({ type: `success`, message: `操作成功` });
            this.back();
          } else {
            this.$message({ type: `success`, message: `${res.errmsg}` });
          }
        })
        .catch(() => {});
    },
    // 查询管辖单位
    async searchOther() {
      let res = await this.deptQuery();
      if (this.$checkRes(res)) {
        this.$set(this, `tube_companyList`, res.data);
      }
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    .one_1 {
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #ccc;
      margin: 0 0 10px 0;
      font-size: 18px;
      font-weight: bold;
    }
    .one_2 {
      .one_2txt {
        border: 1px solid #ccc;
        /deep/.el-form-item {
          margin: 0;
        }
        /deep/.el-date-editor.el-input,
        .el-date-editor.el-input__inner {
          width: 100%;
        }
        /deep/.el-select {
          width: 100%;
        }
        .btn {
          text-align: right;
          padding: 5px 5px;
        }
      }
    }
  }
}
</style>
