<template>
  <el-dialog
    :title="modalTitle"
    :visible.sync="modalVisible"
    :width="formLabelWidth"
    top="2vh"
    @close="handleCancel">
    <div class="mobile">
      <div class="hc-box add">
        <div class="hc-box-header">
          新建核查方案
        </div>
        <div class="hc-box-wrap">
            <el-form label-width="90px" :model="form" :rules="rules" ref="from" class="from">
                <el-form-item label="方案编号:" prop="status">
                    <el-input type="text" v-model="form.remark" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="审核结果:" prop="status">
                    <el-select
                      v-model="form.status"
                      placeholder="请选择"
                      clearable
                      :disabled="limit.isRead"
                      size="small">
                      <el-option
                        v-for="dict in statusOptions"
                        :key="dict.dictValue"
                        :label="dict.dictLabel"
                        :value="dict.dictValue"
                      />
                    </el-select>
                </el-form-item>
                <el-form-item label="备注:">
                    <el-input type="textarea"
                              :rows="3"
                              v-model="form.remark"
                              :disabled="limit.isRead"></el-input>
                </el-form-item>
            </el-form>
        </div>
      </div>
      <div class="hc-box taskList">
        <div class="hc-box-header">
          核查任务 <span class="action">添加</span>
        </div>
        <div class="hc-box-wrap">
            <el-table v-loading="loading" :data="list" border>
              <el-table-column label="序号" type="index" width="50" align="center" />
              <el-table-column label="方案编号" align="center" prop="userName" />
              <el-table-column label="案事件分组" align="center" prop="userName" :show-overflow-tooltip="true" />
              <el-table-column label="核查企业数" align="center" prop="nickName" :show-overflow-tooltip="true" />
              <el-table-column label="创建账号" align="center" prop="dept.deptName" :show-overflow-tooltip="true" />
              <el-table-column label="创建时间" align="center" prop="createTime" width="160">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
              </el-table-column>
              <el-table-column label="状态" align="center" prop="phonenumber" width="120" />
              <el-table-column
                label="操作"
                align="center"
                width="180"
                class-name="small-padding fixed-width"
              >
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="primary"
                    icon="el-icon-download"
                    @click="handleExport(scope.row)"
                    v-hasPermi="['system:user:remove']"
                  >下载</el-button>
                  <el-button
                    size="mini"
                    type="success"
                    icon="el-icon-delete"
                    v-hasPermi="['system:user:remove']"
                  >详情</el-button>
                </template>
              </el-table-column>
            </el-table>
            <pagination
              v-show="total>0"
              :total="total"
              :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />

        </div>
      </div>

    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取 消</el-button>
      <el-button type="primary" @click="submit" v-if="!limit.isRead">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
// import { updateRecordChek } from "@/api/system/recordCheck";
export default {
  name: 'addMobiel',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: 'title'
    },
    action: {
      type: String,
      default: 'add'
    },
    selectRow: {
      type: Object,
      default: {}
    }
  },
  watch: {
    visible(newVal, oldVal) {
      this.modalVisible = newVal;
    },
    title(newVal, oldVal) {
      this.modalTitle = newVal;
    },
    action(newVal, oldVal) {
      this.modalAction = newVal;
    },
    selectRow(newVal, oldVal) {
      this.modalSelectRow = newVal;
    }
  },
  data() {
    return {
      modalTitle: this.title,
      modalVisible: this.visible,
      modalAction: this.action,
      modalSelectRow: this.selectRow,
      formLabelWidth: '1024px',
      //窗口权限
      limit: {
        isRead: false, //是否只读
        isAdd: false //是否可写
      },
      rules: {
        status: [{ required: true, message: '审核结果不能为空!', trigger: 'blur' }]
      },
      total: 0,
      //审核状态
      statusOptions: [],
      // 性别状态数据字典
      sexTypeOptions: [],
      list:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined
      },
      loading:false,
      form: {}
    };
  },
  created() {
    this.initPage();
    this.form = Object.assign({},this.modalSelectRow)
    switch (this.modalAction) {
      case 'add':
        this.limit.isAdd = true;
        break;
      case 'view':
        this.limit.isRead = true;
        break;
      default:
        break;
    }
  },
  methods: {
    //强制视图渲染
    forceUpdate() {
      this.$forceUpdate();
    },
    //初始化默认值
    initPage() {
      //审核字典查询
      this.getDicts("user_ext_status").then(response => {
        this.statusOptions = response.data;
      });
      //性别字典查询
      this.getDicts("sys_user_sex").then(response => {
        this.sexTypeOptions = response.data;
      });
    },
    submit() {
      this.$refs.from.validate(valid => {
        if (valid) {
          let params = {
            id:this.form.id,
            status:this.form.status,
            remark:this.form.remark
          }
          updateRecordChek(params).then(response => {
              if (response.code === 200) {
                this.msgSuccess("操作成功");
                this.modalVisible = false
               	this.$emit('closeModal', true);
              }
          });
        } else {
          return false;
        }
      });
    },
    handleCancel() {
      this.$emit('closeModal', false);
    },
    getList(){

    }
  },
  computed:{
    // 性别状态字典翻译
    sexFormat() {
       return function(val){
         return this.selectDictLabel(this.sexTypeOptions, val);
       }
    }
  }
};
</script>

<style lang="scss" scoped>
  .hc-box{
    border:1px solid #e9e9e9;
    margin-bottom:20px;
    .hc-box-header{
        height:40px;
        line-height:40px;
        background:#fafafa;
        font-weight:bold;
        color:#333;
        padding:0 15px;
        .action{
          margin-left:10px;
          color:#304FFE
        }
    }


  }
  .add{
    .hc-box-wrap{
      padding:15px 30px 15px 0;
    }
  }
  .taskList{
    .hc-box-wrap{
      padding:15px;
    }
  }
</style>
