<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item class="treeselectForm treeselectForm2 treeselectFormzn" label="组织架构" prop="deptIds">
            <tree @treeselectFn="treeselectFn" :treeval="queryParams.deptIds" :ismultiple="true" style="width: 193px;float: left"></tree>
          </el-form-item>
          <el-form-item label="客户姓名" prop="name">
            <el-input v-model="queryParams.name" placeholder="请输入客户姓名" clearable size="mini" @keyup.enter.native="handleQuery"/>
          </el-form-item>
        <el-form-item label="客资线索" prop="cids">
          <el-select v-model="queryParams.cids" clearable collapse-tags multiple placeholder="请选择客资线索" size="mini">
            <el-option v-for="item in summaryTaskOptions" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
          </el-select>
        </el-form-item>
<!--          <el-form-item label="跟进状态" prop="isClose">-->
<!--            <el-select size="mini" v-model="queryParams.isClose" clearable placeholder="请选择跟进状态"><el-option label="跟进中" value="0"></el-option><el-option label="跟进完成" value="1"></el-option></el-select>-->
<!--          </el-form-item>-->
<!--      <el-form-item label="是否跟进" prop="customerClueStatus">-->
<!--        <el-select size="mini" v-model="queryParams.customerClueStatus" clearable placeholder="请选择是否跟进"><el-option label="未跟进" value="0"></el-option><el-option label="已跟进" value="1"></el-option></el-select>-->
<!--      </el-form-item>-->
          <el-form-item label=" " >
            <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">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userSummaryList" >
      <el-table-column :show-overflow-tooltip="true" label="客资线索" prop="cid" width="100">
        <template slot-scope="scope">{{fillObjectFormat(scope.row, scope.column)}}</template>
      </el-table-column>
      <el-table-column label="公司名称"  prop="companyName" :show-overflow-tooltip="true"/>
      <el-table-column label="大区名称"  prop="regionName" :show-overflow-tooltip="true"/>
      <el-table-column label="部门名称"  prop="deptName" :show-overflow-tooltip="true"/>
      <el-table-column label="客户姓名"  prop="name" :show-overflow-tooltip="true"/>

      <el-table-column label="联系电话" align="center" prop="phone" width="110">
        <template slot-scope="scope">{{tell(scope.row.phone)}}</template>
      </el-table-column>
      <el-table-column label="客资接入时间" align="center" prop="createTime" width="150"/>
<!--      <el-table-column :show-overflow-tooltip="true" align="center" label="是否跟进" prop="customerClueStatus" width="100">-->
<!--        <template slot-scope="scope"><span v-if="scope.row.customerClueStatus==1">已跟进</span><span v-else>未跟进</span></template>-->
<!--      </el-table-column>-->
<!--      <el-table-column :show-overflow-tooltip="true" align="center" label="是否完结" prop="isClose" width="100">-->
<!--        <template slot-scope="scope"><span v-if="scope.row.isClose==1">已完结</span><span v-else>未完结</span></template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="80" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleView(scope.row)" v-hasPermi="['sfa:userSummary:query']">转交其他组织</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"
    />


    <!-- 任务详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1024px" append-to-body>
      <el-descriptions title="" border>
        <el-descriptions-item label="客资线索">
          {{fillObjectFormat(form, "")}}
        </el-descriptions-item>
        <el-descriptions-item label="公司名称">
          {{form.companyName}}
        </el-descriptions-item>
        <el-descriptions-item label="大区名称">
          {{form.regionName}}
        </el-descriptions-item>
        <el-descriptions-item label="部门">
          {{form.deptName}}
        </el-descriptions-item>
        <el-descriptions-item label="省">
          {{form.provinceName}}
        </el-descriptions-item>
        <el-descriptions-item label="市">
          {{form.cityName}}
        </el-descriptions-item>
        <el-descriptions-item label="县/区">
          {{form.countryName}}
        </el-descriptions-item>
        <el-descriptions-item label="客户姓名">{{form.name}}</el-descriptions-item>
        <el-descriptions-item label="来电电话">{{tell(form.phone)}}</el-descriptions-item>
        <el-descriptions-item label="目前经营的行业">
          {{form.industry}}
        </el-descriptions-item>
        <el-descriptions-item label="目前经营的品牌">
          {{form.brand}}
        </el-descriptions-item>
        <el-descriptions-item label="有无涂料从业经验">
          <span v-if="form.physicalStore==1">有</span><span v-if="form.physicalStore==2">无</span>
        </el-descriptions-item>
        <el-descriptions-item label="目前有无实体店">
          <span v-if="form.physicalStore==1">有</span><span v-if="form.physicalStore==2">无</span>
        </el-descriptions-item>
        <el-descriptions-item label="产品大类" v-if="form.productCategory">
          {{form.productCategory}}
        </el-descriptions-item>
        <el-descriptions-item label="采购数量" v-if="form.purchaseQuantity">
          {{form.purchaseQuantity}}
        </el-descriptions-item>
        <el-descriptions-item label="客服工号" v-if="form.jobNumber">
          {{form.jobNumber}}
        </el-descriptions-item>
<!--        <el-descriptions-item label="是否完结" v-if="form.isClose">-->
<!--          <span v-if="form.isClose==1">已完结</span><span v-else>未完结</span>-->
<!--        </el-descriptions-item>-->
        <el-form-item label="跟进状态" prop="isClose">
          <el-select size="mini" v-model="queryParams.isClose" clearable placeholder="请选择跟进状态">
            <el-option label="跟进中" value="0"></el-option><el-option label="完成跟进" value="1"></el-option>
          </el-select>
        </el-form-item>
<!--        <el-descriptions-item label="是否跟进" v-if="form.customerClueStatus"><span v-if="form.customerClueStatus==1">已跟进</span><span v-else>未跟进</span></el-descriptions-item>-->
        <el-descriptions-item label="客资接入时间">
          {{form.createTime}}
        </el-descriptions-item>
      </el-descriptions>
      <el-divider></el-divider>
      <el-form ref="answerForm" :model="form" :rules="rules"  size="mini" >
        <el-form-item label="归属销售部" prop="deptId" class="treeselectForm">
          <treeselect v-model="form.deptId" :options="deptOptions"  placeholder="请选择归属销售部" style="width: 200px;float: left"  :disable-branch-nodes="true"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" size="mini">确 定</el-button>
        <el-button @click="open=false" size="mini">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import user from "@/views/components/sfa/user";
import tree from "@/views/components/sfa/treeselectParent";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {getClueInfo, noDeptClueInfoList,updateDept} from "@/api/sfa/clueInfoList";
import {treeselect} from "@/api/system/dept";
export default {
  name: "UserSummary",
  components: { user,tree,Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      openEdit:false,
      // 部门树选项
      deptOptions: undefined,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 主管任务查询表格数据
      userSummaryList: [],
      // 弹出层标题
      title: "",
      datetimerange:[],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptIds:null,
        deptId: null,
        userId: null,
        summaryId: null,
      },
      summaryTaskList:[],
      summaryTaskOptions:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deptId: [
          { required: true, message: "部门未选择", trigger: "change" }
        ],

      },
    };
  },
  created() {
    this.getDicts("customer_clue").then(response => {
      this.summaryTaskOptions = response.data;
    });
    this.getList();
    this.getTreeselect()
  },
  methods: {
    tell(params){
      if(params!=null&&params.length==11){
        return params.substr(0, 3) + '****' + params.substr(7)
      }else{
        return ""
      }
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 填写对象
    fillObjectFormat(row, column) {
      if (row.cid != null) {
        return this.selectDictLabels(this.summaryTaskOptions, row.cid);
      } else {
        return ""
      }
    },
    treeselectFn(val){
      this.queryParams.deptIds = val;
    },
    /** 查询主管任务查询列表 */
    getList() {
      this.loading = true;
      if(this.queryParams.name!=null){
        this.queryParams.name=this.queryParams.name.trim()
      }
      noDeptClueInfoList(this.queryParams).then(response => {
        this.userSummaryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        userSummaryId: null,
        deptId: null,
        userId: null,
        summaryId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.deptIds=null
      this.handleQuery();
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      const userSummaryId = row.customerClueInfoId || this.ids
      getClueInfo({customerClueInfoId:userSummaryId}).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "转发客资";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["answerForm"].validate(valid => {
        if (valid) {
          updateDept({deptId:this.form.deptId,customerClueInfoId:this.form.customerClueInfoId}).then(response => {
            if(response.code==200){
                this.$modal.msgSuccess("转发成功");
                this.open = false;
                this.getList();
            }
              })
        }
      });
    },
  }
};
</script>

