<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
<!--      <el-form-item label="企微员工账号" prop="qwUserId">-->
<!--        <el-input-->
<!--          v-model="queryParams.qwUserId"-->
<!--          placeholder="请输入企微员工账号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="客户名称" prop="externalUserName">
        <el-input
          v-model="queryParams.externalUserName"
          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-row :gutter="10" class="mb8">
    </el-row>

    <el-table border v-loading="loading" :data="sopUserLogsInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" width="100"/>
      <el-table-column label="企微员工账号" align="center" prop="qwUserId" width="100"/>
      <el-table-column label="客户账号" align="center" prop="externalId" width="100"/>
      <el-table-column label="客户名称" align="center" prop="externalUserName" />
      <el-table-column label="添加日期" align="center" prop="createTime" width="180"/>
      <el-table-column label="添加时间" align="center" prop="crtTime" width="180"/>
      <el-table-column label="修改时间" align="center" prop="updateTime" width="180"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改营期</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>
</template>

<script>
import {
  listSopUserLogsInfo,
  getSopUserLogsInfo,
  delSopUserLogsInfo,
  addSopUserLogsInfo,
  updateSopUserLogsInfo,
  exportSopUserLogsInfo,
  sendMsgSop
} from "@/api/qw/sopUserLogsInfo";


export default {
  name: "sopUserLogsInfoDetails",
  data() {
    return {
      //上传语音的遮罩层
      voiceLoading :false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // sopUserLogsInfo表格数据
      sopUserLogsInfoList: [],
      sysFsSopWatchStatus: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sopId: null,
        userLogsId: null,
        userIdParam:null,
        startTimeParam:null,
        externalContactId: null,
        qwUserId: null,
        corpId: null,
        externalId: null,
        fsUserId: null,
        externalUserName: null,
        createTime: null,
      },

      courseList:[],
      videoList:[],
      //插件版
      sysQwSopAiContentType:[],

      sendMsgOpen:{
        title:'一键批量群发',
        open:false,
        ids:null,
      },
      // 表单参数
      form: {},
      setting:[{contentType:'1', value: '',}],
      msgForm:{
        videoId:null,
        courseId:null,
        courseType:null,
        userIdParam:null,
        setting:null,
        ids:null,
        sopId: null,
        startTime: null,
      },
      // 表单校验
      rules: {},
      msgRules:{},
    };
  },
  created() {
    this.getDicts("sys_qwSopAi_contentType").then(response => {
      this.sysQwSopAiContentType = response.data;
    });
    this.getDicts("sys_fs_sop_watch_status").then(response => {
      this.sysFsSopWatchStatus = response.data;
    });

  },
  methods: {
    selectSopUserLogsInfo(val,externalUserName){
      this.loading = true;
      this.queryParams.sopId=val.sopId;
      this.queryParams.userLogsId=val.id;
      if (externalUserName!=null){
        this.queryParams.externalUserName = externalUserName;
      }

      listSopUserLogsInfo(this.queryParams).then(response => {
        this.sopUserLogsInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

      //用于一键群发
      this.queryParams.userIdParam=val.userId;
      this.queryParams.startTimeParam=val.startTime;
      this.queryParams.corpIdParam=val.corpId;

    },
    /** 查询sopUserLogsInfo列表 */
    getList() {
      this.loading = true;
      listSopUserLogsInfo(this.queryParams).then(response => {
        this.sopUserLogsInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sopId: null,
        userLogsId: null,
        externalContactId: null,
        qwUserId: null,
        corpId: null,
        externalId: null,
        fsUserId: null,
        externalUserName: null,
        createTime: null,
        crtTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },


    resetSendMsgSop() {
      this.msgForm = {
        videoId:null,
        courseId:null,
        courseType:null,
        setting:null,
        ids:null,
      };
      this.resetForm("msgForm");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加客户营期";
    },


    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSopUserLogsInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改客户营期";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSopUserLogsInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.$emit('flashNotify')
            });
          } else {
            addSopUserLogsInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除sopUserLogsInfo编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSopUserLogsInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有sopUserLogsInfo数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportSopUserLogsInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
