<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="100px">
              <el-col :span="24" class="one_2txt">
                <el-col :span="8">
                  <el-form-item label="发布单位">
                    <el-input v-model="searchFrom.release_company"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="发布时间">
                    <el-date-picker
                      v-model="searchFrom['start@release_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@release_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-input v-model="searchFrom.title"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="发布人">
                    <el-input v-model="searchFrom.release_personal"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="是否撤销">
                    <el-select v-model="searchFrom.revoke" clearable placeholder="请选择">
                      <el-option label="否" value="0"></el-option>
                      <el-option label="是" value="1"></el-option>
                    </el-select>
                  </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.industry_type" clearable placeholder="请选择">
                      <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>
                  <download-excel :data="selected" :fields="xctb_fields.fields" :name="xctb_fields.name" style="display: inline; margin: 0 0 0 10px">
                    <el-button type="primary" size="mini">批量导出</el-button>
                  </download-excel>
                </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"
            @revoke="toRevoke"
            :select="true"
            :selected="selected"
            @handleSelect="handleSelect"
          >
          </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const { xctb_base } = require('@common/src/layout/deploy/dict');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: assistance_investigation } = createNamespacedHelpers('assistance_investigation');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      // 查询
      searchFrom: {},
      // 列表
      fields: [
        { label: '标题', model: 'title' },
        { label: '发布人', model: 'release_personal' },
        { label: '发布单位', model: 'release_company' },
        { label: '发布时间', model: 'release_date' },
        { label: '是否撤销', model: 'revoke', format: (i) => (i == '0' ? '否' : '是') },
      ],
      opera: [
        { label: '维护', method: 'edit' },
        { label: '撤销', method: 'revoke', display: (i) => i.revoke == '0' },
      ],
      xctb_fields: xctb_base,
      list: [],
      total: 0,
      // 批量导出列表
      selected: [],
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...assistance_investigation(['query', 'update']),
    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/notification/xctbgl/add' });
    },
    // 维护
    toEdit({ data }) {
      this.$router.push({ path: '/adminPolice/notification/xctbgl/add', query: { id: data.id } });
    },
    // 撤销
    async toRevoke({ data }) {
      this.$confirm(`您确认提交撤销吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          data.revoke = '1';
          let res = await this.update(data);
          if (this.$checkRes(res)) {
            this.$message({ type: `success`, message: `操作成功` });
            this.search();
          } else {
            this.$message({ type: `success`, message: `${res.errmsg}` });
          }
        })
        .catch(() => {});
    },
    // 批量导出
    handleSelect(data) {
      this.$set(this, `selected`, 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>
