<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-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" @view="toView" @reply="toReply"> </data-table>
        </el-col>
      </el-col>
    </el-row>
    <el-dialog class="dialog" title="信息详情" :visible.sync="show" width="60%" :before-close="close" :close-on-click-modal="false">
      <info-1 :info="info"></info-1>
    </el-dialog>
    <el-dialog class="dialog" title="回复查看" :visible.sync="twoShow" width="60%" :before-close="twoClose" :close-on-click-modal="false">
      <data-table :fields="replyFields" :opera="replyOpera" :data="replyList" :usePage="false"> </data-table>
    </el-dialog>
  </div>
</template>

<script>
import info1 from '../parts/info-1.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: assistance_investigation } = createNamespacedHelpers('assistance_investigation');
const { mapActions: assistance_investigation_reply } = createNamespacedHelpers('assistance_investigation_reply');

export default {
  name: 'index',
  props: {},
  components: { info1 },
  data: function () {
    return {
      // 查询
      searchFrom: {},
      // 列表
      fields: [
        { label: '标题', model: 'title' },
        { label: '发布人', model: 'release_personal' },
        { label: '发布单位', model: 'release_company' },
        { label: '发布时间', model: 'release_date' },
      ],
      opera: [
        { label: '详情', method: 'view' },
        { label: '回复查看', method: 'reply' },
      ],
      list: [],
      total: 0,
      // 批量导出
      selected: [],
      // 详情
      show: false,
      info: {},
      // 回复查看
      twoShow: false,
      replyFields: [
        { label: '回复人', model: 'reply_personal' },
        { label: '回复时间', model: 'reply_date' },
        { label: '回复内容', model: 'reply_content' },
      ],
      replyOpera: [],
      replyList: [],
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...assistance_investigation(['query', 'update']),
    ...assistance_investigation_reply({ replyQuery: 'query' }),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      const condition = _.cloneDeep(this.searchFrom);
      let res = await this.query({ skip, limit, revoke: '0', ...condition, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 详情
    toView({ data }) {
      this.$set(this, `info`, data);
      this.show = true;
    },
    // 关闭详情
    close() {
      this.show = false;
    },
    // 回复查看
    async toReply({ data }) {
      let res = await this.replyQuery({ assistance_id: data.id });
      if (this.$checkRes(res)) {
        this.$set(this, `replyList`, res.data);
        this.twoShow = true;
      }
    },
    // 关闭回复
    twoClose() {
      this.twoShow = false;
    },
  },
  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;
        }
      }
    }
  }
}
.dialog {
  /deep/.el-dialog__body {
    padding: 10px;
  }
}
</style>
