<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="模板标题" prop="name">
        <el-input
          v-model="queryParams.name"
          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-table v-loading="loading" :data="sopTempList" ref="sopTempList" >
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="模板标题" align="center" prop="name" />
      <el-table-column label="每天首条消息是否发课" align="center" prop="name" v-if="cuoser">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.cuoser" type="success">是</el-tag>
          <el-tag v-if="!scope.row.cuoser" type="danger">否</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="medium"
            type="primary"
            plain
            icon="el-icon-edit"
            @click="handleSopTemp(scope.row)"
            v-hasPermi="['qw:sopTemp:edit', 'qw:sopTemp:myEdit', 'qw:sopTemp:deptEdit']"
          >选择此模板</el-button>
        </template>
      </el-table-column>
    </el-table>

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

<script>
import { listSopTemp,listSopTempDeptList,listSopTempMyList } from "../../../api/qw/sopTemp";

export default {
  name: "SopTempComments",
  data() {
    return {
      isUpdateSop:null,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // sop模板表格数据
      sopTempList: [],
      sysQwSopType:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      cuoser: false,
      // 状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        sendType:null,
        status:1,
      },
      formType:null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {

    this.getDicts("sys_company_status").then(response => {
      this.statusOptions = response.data;
    });

    this.getDicts("sys_qw_sop_type").then(response => {
      this.sysQwSopType = response.data;
    });
  },
  methods: {
    /** 查询sop模板列表 */
    getList(sendType,isUpdate,cuoser,formType) {


      if(cuoser == null){
        cuoser = false;
      }
      this.isUpdateSop = isUpdate;
      this.cuoser = cuoser;
      this.loading = true;
      this.queryParams.sendType= sendType;
      this.queryParams.cuoser= cuoser;
      this.formType= formType;

      if (formType==2 || formType==3) {
        listSopTempDeptList(this.queryParams).then(response => {
          this.sopTempList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      } else {
        listSopTemp(this.queryParams).then(response => {
          this.sopTempList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      }
    },

    getResetList(){
      this.loading = true;
      if (this.formType==2 || this.formType==3) {
        listSopTempDeptList(this.queryParams).then(response => {
          this.sopTempList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      } else {
        listSopTemp(this.queryParams).then(response => {
          this.sopTempList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    handleSopTemp(val){
      if (this.isUpdateSop === 1){
        this.$emit("submitUpdateTemp",val)
        this.$refs.sopTempList.clearSelection();
      }else {
        this.$emit("sopTemp",val)
        this.$refs.sopTempList.clearSelection();
        this.open=false;
      }
    },
    // 表单重置
    reset() {
      this.form = {
        pageNum: 1,
        pageSize: 10,
        name: null,
        status:1,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getResetList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },


  }
};
</script>
