<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="任务" prop="taskCode">
        <el-input
          v-model="queryParams.taskCode"
          placeholder="请输入任务编码"
          clearable
          @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="behaviorList" height="700px">
      <el-table-column label="负责人" align="center" prop="staffName" />
      <el-table-column label="行动日期" align="center" prop="time" />
      <el-form-item label="行动日期" prop="time">
        <el-date-picker clearable
          v-model="form.time"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择行动日期">
        </el-date-picker>
      </el-form-item>
      <el-table-column label="联系人" align="center" prop="linkmanName" />
      <el-table-column label="拜访效果" align="center" prop="result" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mk_bo_behavior_res" :value="scope.row.result"/>
        </template>
      </el-table-column>
      <el-table-column label="是否上级协助" align="center" prop="assist" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.assist"/>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="协助内容" align="center" prop="assistContent" />
      <el-table-column show-overflow-tooltip label="洽谈内容" align="center" prop="content" />
      <el-table-column width="150" label="任务编码" align="center" prop="taskCode"/>
      <el-table-column label="行动类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mk_bo_behavior_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="客户" align="center" prop="customerName"/>
      <el-table-column label="拜访目的" align="center" prop="purpose">
        <template slot-scope="scope">
            <dict-tag :options="dict.type.mk_bo_behavior_goal" :value="scope.row.purpose"/>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="销售组织" align="center" prop="salesOrgName"/>
      <el-table-column show-overflow-tooltip label="部门" align="center" prop="deptName"/>
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
       <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleBrowse(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"
    />
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :disabled="this.operatingState == 'Browse'">
        <el-divider content-position="left">
          <dev style="width: 50px; height: 40px; font-size: 18px">基本信息</dev>
        </el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item label="任务" prop="taskId" v-if="!(this.source == 'BoDetails')">
              <el-input v-model="form.taskCode" placeholder="请输入任务" :disabled="this.source == 'TaskList'"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="行动类型" prop="type">
              <el-select v-model="form.type" placeholder="请输入行动类型">
                <el-option
                  v-for="dict in dict.type.mk_bo_behavior_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="行动日期" prop="time">
              <el-date-picker clearable
                v-model="form.time"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择行动日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="客户" prop="customerName">
              <el-input v-model="form.customerName" placeholder="请输入客户" disabled="this.source == 'BoDetails' || this.source == 'TaskList'"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人" prop="linkmanName">
              <el-input v-model="form.linkmanName" placeholder="请输入联系人" >
                <el-button slot="append" icon="el-icon-more" @click="refereContact"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="拜访目的" prop="purpose">
              <el-select v-model="form.purpose" placeholder="请输入拜访目的">
                <el-option
                  v-for="dict in dict.type.mk_bo_behavior_goal"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col  :span="8">
            <el-form-item label="拜访效果" prop="result">
              <el-select v-model="form.result" placeholder="请输入拜访效果">
                <el-option
                  v-for="dict in dict.type.mk_bo_behavior_res"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="是否上级协助" prop="assist">
              <el-select v-model="form.assist" placeholder="请输入是否上级协助">
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="协助内容" prop="assistContent" v-show="form.assist == 'Y'" :rules="form.assist == 'Y' ? rules.assistContent : [{require: false}]">
              <el-input v-model="form.assistContent" placeholder="请输入协助内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="销售区域" prop="marketingAreaName">
              <el-input v-model="form.marketingAreaName" placeholder="请输入销售区域">
                <el-button slot="append" icon="el-icon-more" @click="refereSaleaea"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col  :span="8">
            <el-form-item label="销售组织" prop="salesOrgName">
              <el-input v-model="form.salesOrgName" placeholder="请输入销售组织" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col  :span="8">
             <el-form-item label="部门" prop="deptName">
              <el-input v-model="form.deptName" placeholder="请输入部门" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="负责人" prop="staffName">
              <el-input v-model="form.staffName" placeholder="请输入负责人" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">
          <dev style="width: 50px; height: 40px; font-size: 18px">跟进内容</dev>
        </el-divider>
        <el-form-item label="内容" prop="content" >
          <el-input
            type="textarea"
            :rows="2"
            maxlength=900
            placeholder="填写提示：今天拜访了谁，收集了什么述求，达成了什么结果，下一步计划。"
            autosize
            v-model="form.content">
          </el-input>
        </el-form-item>
        <el-divider content-position="left">
          <dev style="width: 50px; height: 40px; font-size: 18px">照片信息</dev>
        </el-divider>

        <el-upload
          action="actionUrl"
          list-type="picture-card"
          :on-change="uploadPic"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove"
          :auto-upload="false"
          :file-list="fileList"
          >
          <i class="el-icon-plus"></i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>

        <div class="md-auditInfo">
          <el-divider content-position="left">
            <dev style="width: 50px; height: 40px; font-size: 18px">其它信息</dev>
          </el-divider>
          <el-form :inline="true" label-position="right" :model="form">
            <el-row>
              <el-col :span="6">
                <el-form-item label="创建人">
                  <el-input v-model="form.createByName" size="small" readonly></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="创建时间">
                  <el-input v-model="form.createTime" size="small" readonly></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="修改人">
                  <el-input v-model="form.updateByName" size="small" readonly></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="修改时间">
                  <el-input v-model="form.updateTime" size="small" readonly></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="this.operatingState != 'Browse'" :disabled="submitButtonEditStatus">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBehavior, getBehavior} from "@/api/business/spd/bo/behavior";

export default {
  name: "Behavior",
  dicts: ['mk_bo_behavior_res','mk_bo_behavior_type','sys_yes_no','mk_bo_behavior_goal'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 行动表格数据
      behaviorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskId: null,
        type: null,
        time: null,
        customer: null,
        customerName: null,
        linkman: null,
        linkmanName: null,
        purpose: null,
        result: null,
        assist: null,
        assistContent: null,
        salesOrg: null,
        salesOrgName: null,
        dept: null,
        deptName: null,
        staff: null,
        staffName: null,
        content: null,
        tenantId: null,
        revision: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询行动列表 */
    getList() {
      this.loading = true;
      listBehavior(this.queryParams).then(response => {
        this.behaviorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查看按钮操作 */
    handleBrowse(row) {
      this.reset();
      const id = row.id || this.ids
      getBehavior(id).then(response => {
        this.form = response.data;
        this.fileList = this.form.behaviorPs;
        this.open = true;
        this.operatingState = "Browse";
        this.title = "基础信息";
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        taskCode: null,
        type: null,
        time: null,
        customer: null,
        customerName: null,
        linkman: null,
        linkmanName: null,
        purpose: null,
        result: null,
        assist: null,
        assistContent: null,
        salesOrg: null,
        salesOrgName: null,
        dept: null,
        deptName: null,
        staff: null,
        staffName: null,
        content: null,
        tenantId: null,
        revision: 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.handleQuery();
    },
  }
};
</script>
