<template>
  <div class="app-container">
    <div class="search-bx">
      <div class="search">
        <el-row :gutter="0">
          <el-input
            v-model="tableObj.getdataListParm.parammaps.travelCode"
            placeholder="出差单编号"
            class="filter-item"
            style="width: 120px"
          />

          <el-select
            v-model="tableObj.getdataListParm.parammaps.employeeId"
            placeholder="出差人"
            class="filter-item"
            style="width: 120px"
            clearable
            filterable
          >
            <el-option
              v-for="item in empNameList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-input
            v-model="tableObj.getdataListParm.parammaps.customerName"
            placeholder="客户名称"
            style="width: 180px"
            class="filter-item"
            clearable
          />

          <!-- <el-autocomplete v-model="tableObj.getdataListParm.parammaps.customerName" :fetch-suggestions="customer_search" placeholder="客户名称" style="width: 200px;margin-right:10px" @select="change_customer_select" @clear="clear_customer_select" @blur="customer_search_blur" clearable>
                <template slot-scope="{ item }">
                  <span class="name">{{ item.name }}</span>
                </template>
              </el-autocomplete> -->

          <el-select
            v-model="tableObj.getdataListParm.parammaps.groupId"
            placeholder="集团"
            class="filter-item"
            style="width: 120px"
            clearable
          >
            <el-option
              v-for="item in groupNameList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-date-picker
            v-model="tableObj.getdataListParm.parammaps.inputDatetime1"
            class="inputDatetime filter-item"
            type="daterange"
            range-separator="至"
            start-placeholder="创建时间"
            end-placeholder="创建时间"
            style="width: 250px"
          />

          <el-select
            v-model="tableObj.getdataListParm.parammaps.statusName"
            placeholder="出差单状态"
            class="filter-item"
            style="width: 120px"
            clearable
          >
            <el-option
              v-for="item in statusNameList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-input
            v-model="tableObj.getdataListParm.parammaps.beginServiceCost"
            placeholder="计划费用"
            style="width: 80px"
          ></el-input>
          -
          <el-input
            v-model="tableObj.getdataListParm.parammaps.endServiceCost"
            placeholder="计划费用"
            style="width: 80px"
          ></el-input>

          <el-date-picker
            v-model="tableObj.getdataListParm.parammaps.inputDatetime2"
            class="inputDatetime filter-item"
            type="daterange"
            range-separator="至"
            start-placeholder="计划开始时间"
            end-placeholder="计划开始时间"
            style="width: 250px"
          />

          <el-date-picker
            v-model="tableObj.getdataListParm.parammaps.inputDatetime3"
            class="inputDatetime filter-item"
            type="daterange"
            range-separator="至"
            start-placeholder="计划结束时间"
            end-placeholder="计划结束时间"
            style="width: 250px"
          />

          <el-button class="successBorder" @click="form_search">查询</el-button>
          <el-button class="successBorder" @click="form_clear">重置</el-button>
        </el-row>
      </div>
    </div>

    <div class="table">
      <el-table
        :key="tableObj.tableKey"
        v-loading="tableObj.listLoading"
        element-loading-text="给我一点时间"
        :data="tableObj.list"
        border
        fit
        highlight-current-row
        style="width: 100%"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        class="elTable table-fixed"
        :max-height="myHeight"
      >
        <!-- <el-table-column type="selection" align="center" width="50" /> -->
        <el-table-column
          label="序号"
          align="center"
          type="index"
          width="50px"
          fixed="left"
        >
          <template slot-scope="scope">
            <span>{{
              scope.$index + (tableObj.pageNum - 1) * tableObj.pageSize + 1
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="出差单编号"
          min-width="110px"
          align="center"
          fixed="left"
        >
          <template slot-scope="scope">
            <span
              style="color: #409eff; cursor: pointer"
              @click="form_see(scope.row)"
              >{{ scope.row.travelCode }}</span
            >
          </template>
        </el-table-column>
        <el-table-column
          label="出差单状态"
          min-width="110px"
          align="center"
          fixed="left"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.statusName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="出差人"
          min-width="90px"
          align="center"
          fixed="left"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.employeeName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="出差目的" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.reason }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="计划开始时间"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.planBeginDate }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="计划结束时间"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.planSuccessDate }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="计划费用(元)"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.serviceCost }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="目的地"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.adress }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="客户名称"
          min-width="120px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.customerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="所属集团" min-width="120px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.groupName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="备注"
          min-width="120px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
          :width="autoWidth"
          v-if="autoWidth !== 0"
          class-name="small-padding fixed-width"
          fixed="right"
        >
          <template slot-scope="{ row }">
            <el-button
              class="miniSuccess"
              @click="form_adopt(row)"
              v-if="roleSet(row)"
              >通过</el-button
            >

            <el-button
              class="miniDanger"
              @click="form_reject(row)"
              v-if="roleSet(row)"
              >驳回</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="tableObj.total >= 0"
        :total="tableObj.total"
        :page.sync="tableObj.getdataListParm.offset"
        :limit.sync="tableObj.getdataListParm.pagecount"
        @pagination="get_table_data"
      />
    </div>

    <!-- 新增/编辑 -->
    <el-dialog
      :title="textMap[create.dialogStatus]"
      :visible.sync="create.dialogFormVisible"
      :close-on-click-modal="false"
      width="50%"
      :before-close="dialog_close"
    >
      <div class="app-add">
        <el-form
          ref="temp"
          :rules="create.rules"
          :model="create.temp"
          label-position="right"
          label-width="150px"
          style="width: 80%; margin: 0 auto 50px"
        >
          <el-form-item
            label="出差人"
            prop="employeeName"
            v-if="create.dialogStatus == 'see'"
          >
            <el-input
              ref="employeeName"
              v-model="create.temp.employeeName"
              class="filter-item"
              style="width: 100%"
              disabled
            />
          </el-form-item>

          <el-form-item label="计划出差时间：" prop="inputDatetime2">
            <el-date-picker
              v-model="create.temp.inputDatetime2"
              class="inputDatetime filter-item"
              type="daterange"
              range-separator="至"
              start-placeholder="计划出差时间"
              end-placeholder="计划出差时间"
              style="width: 100%"
              disabled
            />
          </el-form-item>

          <el-form-item label="计划费用(元)：" prop="serviceCost">
            <el-input
              ref="serviceCost"
              v-model="create.temp.serviceCost"
              placeholder=""
              class="filter-item"
              style="width: 100%"
              disabled
            />
          </el-form-item>

          <el-form-item label="所属集团：" prop="groupId">
            <el-select
              v-model="create.temp.groupId"
              placeholder="所属集团"
              class="filter-item"
              style="width: 100%"
              filterable
              @change="change_group"
              clearable
              disabled
            >
              <el-option
                v-for="item in groupNameList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="客户名称：" prop="customerId">
            <el-select
              v-model="create.temp.customerId"
              filterable
              placeholder="客户名称"
              class="filter-item"
              style="width: 100%"
              clearable
              @change="change_customer"
              disabled
            >
              <el-option
                v-for="item in create.customerNameList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="目的地" prop="adress">
            <el-input
              ref="adress"
              v-model="create.temp.adress"
              class="filter-item"
              style="width: 100%"
              disabled
            />
          </el-form-item>

          <el-form-item label="出差目的：" prop="reason">
            <el-input
              ref="reason"
              v-model="create.temp.reason"
              type="textarea"
              :autosize="{ minRows: 4, maxRows: 8 }"
              :rows="8"
              placeholder="请输入备注，最多200个字"
              maxlength="200"
              class="filter-item"
              style="width: 100%"
              disabled
            />
          </el-form-item>

          <el-form-item label="备注：" prop="remark">
            <el-input
              ref="remark"
              v-model="create.temp.remark"
              type="textarea"
              :autosize="{ minRows: 4, maxRows: 8 }"
              :rows="8"
              placeholder="请输入备注，最多200个字"
              maxlength="200"
              class="filter-item"
              style="width: 100%"
              disabled
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button
            class="success"
            v-if="roleSet(create.temp)"
            @click="form_adopt(create.temp)"
            >审核通过</el-button
          >
          <el-button
            class="success"
            v-if="roleSet(create.temp)"
            @click="form_reject(create.temp)"
            >驳回</el-button
          >
          <el-button class="cancelClose" @click="dialog_close()"
            >关闭</el-button
          >
        </div>
      </div>
    </el-dialog>

    <!-- 通过 -->
    <el-dialog
      title="确认是否审核通过"
      :visible.sync="adopt.dialogFormVisible"
      :close-on-click-modal="false"
      width="40%"
      :before-close="dialog_close_adopt"
    >
      <div class="app-add">
        <el-form
          ref="adopttemp"
          :rules="adopt.rules"
          :model="adopt.temp"
          label-position="right"
          label-width="150px"
          style="width: 80%; margin: 0 auto 50px"
        >
          <el-form-item label="备注：" prop="remark">
            <el-input
              ref="remark"
              v-model="adopt.temp.remark"
              type="textarea"
              :autosize="{ minRows: 4, maxRows: 8 }"
              :rows="8"
              placeholder="请输入备注，最多200个字"
              maxlength="200"
              class="filter-item"
              style="width: 100%"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="dialog_close_adopt()"
            >关闭</el-button
          >
          <el-button class="success" @click="form_adopt_save()">确认</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 驳回 -->
    <el-dialog
      title="是否驳回申请"
      :visible.sync="reject.dialogFormVisible"
      :close-on-click-modal="false"
      width="40%"
      :before-close="dialog_close_reject"
    >
      <div class="app-add">
        <el-form
          ref="rejecttemp"
          :rules="reject.rules"
          :model="reject.temp"
          label-position="right"
          label-width="150px"
          style="width: 80%; margin: 0 auto 50px"
        >
          <el-form-item label="驳回原因：" prop="remark">
            <el-input
              ref="remark"
              v-model="reject.temp.remark"
              type="textarea"
              :autosize="{ minRows: 4, maxRows: 8 }"
              :rows="8"
              placeholder="请输入备注，最多200个字"
              maxlength="200"
              class="filter-item"
              style="width: 100%"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="dialog_close_reject()"
            >关闭</el-button
          >
          <el-button class="success" @click="form_reject_save()"
            >确认</el-button
          >
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  GetDataByName,
  PostDataByName,
  failproccess,
  ExecDataByConfig,
  GetDataByNames,
  checkButtons,
  calculativeWidth,
  wxpush,
} from "@/api/common";
import Cookies from "js-cookie";
import { parseTime } from "@/utils/index.js";
import Pagination from "@/components/Pagination";
import { MessageBox } from "element-ui";
export default {
  name: "BusinessTravelApproval",
  components: { Pagination },
  data() {
    return {
      myHeight: document.documentElement.clientHeight - 85 - 160,
      autoWidth: 220,

      employeid: Cookies.get("employeid"),

      g_userId: Cookies.get("g_userId"),
      isRoleEdit: [],
      isBusinessAdopt: [],

      rowData: {},
      isHome: "",

      send_select_list: [
        // { name: 'getCustomerSelect', offset: 0, pagecount: 0, parammaps: {} },
        {
          name: "getDictListSelect1",
          offset: 0,
          pagecount: 0,
          parammaps: { pid: "54" },
        },
        {
          name: "getUserFuzzy",
          offset: 0,
          pagecount: 0,
          parammaps: { inputvalue: "" },
        },
      ],

      // 下拉框 - 客户名称
      customerNameList: [],

      // 下拉框 - 集团
      groupNameList: [],

      // 下拉框 - 出差人

      empNameList: [],

      // 下拉框 - 出差单
      statusNameList: [
        { name: "草稿", id: "草稿" },
        { name: "一审中", id: "一审中" },
        { name: "二审中", id: "二审中" },
        { name: "三审中", id: "三审中" },
        { name: "审核通过", id: "审核通过" },
        { name: "已撤销", id: "已撤销" },
        { name: "被驳回", id: "被驳回" },
      ],

      //表格 - 列表 - 查询
      tableObj: {
        getdataListParm: {
          name: "getBusinessTravelApproval",
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: "Map",
          parammaps: {
            roleId: Cookies.get("g_roleId"),
            userId: Cookies.get("g_userId"),
            travelCode: "",
            customerId: "",
            customerName: "",
            groupId: "",
            statusName: "",
            employeeId: "",

            inputDatetime1: "",
            inputDatetime2: "",
            inputDatetime3: "",

            begainCreaterDate: "",
            endCreaterDate: "",
            beginPlanBeginDate: "",
            endPlanBeginDate: "",
            beginPlanSuccessDate: "",
            endPlanSuccessDate: "",

            beginServiceCost: "",
            endRemoteCost: "",
          },
        },
        tableKey: 0,
        list: [
          {
            id: 1,
          },
        ],
        total: 0,
        listLoading: false,
        temp: {},
      },
      tableSumMoney: 1000,

      // 新增/编辑
      create: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: {
          customerId: "",
          groupId: "",
          groupName: "",
          employeeId: "",
          inputDatetime2: "",
          planBeginDate: "",
          planSuccessDate: "",
          serviceCost: "",
          adress: "",
          reason: "",
          adress: "",
          remark: "",
          modifyName: "",
          id: "",
          userIds: "",
        },

        rules: {
          customerName: [{ required: true, message: "必填", trigger: "blur" }],
          // remoteBeginDate: [{ required: true, message: '必填', trigger: 'blur' }],
          // visiterId: [{ required: true, message: '必填', trigger: 'blur' }],
          // employeeId: [{ required: true, message: '必填', trigger: 'blur' }],
          // receiverName: [{ required: true, message: '必填', trigger: 'blur' }],
          // content: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
        },

        // 客户名称
        getdataListParmCust: {
          name: "getCustomerByGroupId",
          returntype: "Map",
          parammaps: { groupId: "" },
        },
        customerNameList: [],
      },

      // 通过
      adopt: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: { remark: "", id: "", contractStatus: "", statusName: "" },
        rules: {
          remark: [{ required: true, message: "必填", trigger: "blur" }],
        },
      },
      // 驳回
      reject: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: { remark: "", id: "", contractStatus: "", statusName: "" },
        rules: {
          remark: [{ required: true, message: "必填", trigger: "blur" }],
        },
      },

      textMap: {
        create: "新增",
        see: "查看",
        update: "编辑",
      },

      requestParam: {},
      isokDisable: false,
      selectList: [],
      rowStyle: { maxHeight: 50 + "px", height: 45 + "px" },
      cellStyle: { padding: 0 + "px" },
    };
  },

  created() {
    this.get_select_list();
    this.get_auto_buttons();
    var rowData = this.$route.params.rowData;
    var isHome = this.$route.params.isHome;
    var codeNum = this.$route.params.codeNum;

    if (isHome == "home") {
      this.rowData = rowData;
      this.isHome = isHome;
      this.tableObj.getdataListParm.parammaps.travelCode = codeNum;
      this.get_table_data();
    } else {
      this.rowData = {};
      this.isHome = "";
      this.tableObj.getdataListParm.parammaps.travelCode = "";

      this.get_table_data();
    }
  },

  methods: {
    roleSet(row) {
      var result = true;
      console.log(row.userIds);

      if (row.userIds) {
        if (
          this.isBusinessAdopt &&
          row.userIds.split(",").includes(this.g_userId)
        ) {
          result = true;
        } else {
          result = false;
        }
      } else {
        result = false;
      }
      // if(this.isRoleEdit  == '1' && row.userIds.split(',').includes(this.g_userId)){
      //   result = true
      // } else{
      //   result = false
      // }
      return result;
    },
    //获取按钮权限
    get_auto_buttons() {
      const Edit = "BusinessTravelApproval";
      const isRoleEdit = checkButtons(
        JSON.parse(sessionStorage.getItem("buttons")),
        Edit
      );
      this.isRoleEdit = isRoleEdit;

      const BusinessAdopt = "approval:business:adopt";
      const isBusinessAdopt = checkButtons(
        JSON.parse(sessionStorage.getItem("buttons")),
        BusinessAdopt
      );
      this.isBusinessAdopt = isBusinessAdopt;
    },
    //获取所有下拉框的内容
    get_select_list() {
      GetDataByNames(this.send_select_list).then((response) => {
        // this.customerNameList = response.data.getCustomerSelect.list
        // console.log("客户名称下拉框", this.houseNameList)
        this.groupNameList = response.data.getDictListSelect1.list;
        console.log("集团下拉框", this.groupNameList);

        this.empNameList = response.data.getUserFuzzy.list;
        console.log("出差人下拉框", this.empNameList);
      });
    },
    //加载表格
    get_table_data() {
      var me = this;
      this.tableObj.listLoading = true;
      console.log(
        "this.tableObj.getdataListParm======>",
        this.tableObj.getdataListParm
      );
      GetDataByName(this.tableObj.getdataListParm).then((response) => {
        console.log("table数据======>", response.data.list);
        if (response.data.list !== null) {
          this.tableObj.list = response.data.list;
          this.tableObj.pageNum = response.data.pageNum;
          this.tableObj.pageSize = response.data.pageSize;
          this.tableObj.total = response.data.total;

          //计算操作栏宽度
          var btnNum = 0;
          var arrList = response.data.list;
          arrList.forEach(function (row) {
            var itemBtnNum = 0;
            if (me.roleSet(row)) {
              itemBtnNum = itemBtnNum + 2;
            }

            console.log(itemBtnNum);
            if (itemBtnNum > btnNum) {
              btnNum = itemBtnNum;
            }
          });

          console.log("btnNum=============", btnNum);
          me.autoWidth = btnNum * 90;
        } else {
          this.tableObj.list = [];
        }
        setTimeout(() => {
          this.tableObj.listLoading = false;
        }, 100);
      });

      var send_price = {
        name: "getRemoteOfPrice",
        parammaps: this.tableObj.getdataListParm.parammaps,
      };

      GetDataByName(send_price).then((response) => {
        console.log("table总价格数据======>", response);
        if (response.data.list !== null) {
          this.tableSumMoney = response.data.list[0].totlePrice;
        } else {
          this.tableSumMoney = "";
        }
      });
    },
    form_search() {
      console.log("点击了查询");

      if (
        this.tableObj.getdataListParm.parammaps.inputDatetime1 !== "" &&
        this.tableObj.getdataListParm.parammaps.inputDatetime1 !== null
      ) {
        this.tableObj.getdataListParm.parammaps.begainCreaterDate = parseTime(
          this.tableObj.getdataListParm.parammaps.inputDatetime1[0],
          "{y}-{m}-{d}"
        );
        this.tableObj.getdataListParm.parammaps.endCreaterDate = parseTime(
          this.tableObj.getdataListParm.parammaps.inputDatetime1[1],
          "{y}-{m}-{d}"
        );
      } else {
        this.tableObj.getdataListParm.parammaps.inputDatetime1 = "";
        this.tableObj.getdataListParm.parammaps.begainCreaterDate = "";
        this.tableObj.getdataListParm.parammaps.endCreaterDate = "";
      }

      if (
        this.tableObj.getdataListParm.parammaps.inputDatetime2 !== "" &&
        this.tableObj.getdataListParm.parammaps.inputDatetime2 !== null
      ) {
        this.tableObj.getdataListParm.parammaps.beginPlanBeginDate = parseTime(
          this.tableObj.getdataListParm.parammaps.inputDatetime2[0],
          "{y}-{m}-{d}"
        );
        this.tableObj.getdataListParm.parammaps.endPlanBeginDate = parseTime(
          this.tableObj.getdataListParm.parammaps.inputDatetime2[1],
          "{y}-{m}-{d}"
        );
      } else {
        this.tableObj.getdataListParm.parammaps.inputDatetime2 = "";
        this.tableObj.getdataListParm.parammaps.beginPlanBeginDate = "";
        this.tableObj.getdataListParm.parammaps.endPlanBeginDate = "";
      }

      if (
        this.tableObj.getdataListParm.parammaps.inputDatetime3 !== "" &&
        this.tableObj.getdataListParm.parammaps.inputDatetime3 !== null
      ) {
        this.tableObj.getdataListParm.parammaps.beginPlanSuccessDate =
          parseTime(
            this.tableObj.getdataListParm.parammaps.inputDatetime3[0],
            "{y}-{m}-{d}"
          );
        this.tableObj.getdataListParm.parammaps.endPlanSuccessDate = parseTime(
          this.tableObj.getdataListParm.parammaps.inputDatetime3[1],
          "{y}-{m}-{d}"
        );
      } else {
        this.tableObj.getdataListParm.parammaps.inputDatetime3 = "";
        this.tableObj.getdataListParm.parammaps.beginPlanSuccessDate = "";
        this.tableObj.getdataListParm.parammaps.endPlanSuccessDate = "";
      }

      this.tableObj.getdataListParm.offset = 1;
      this.get_table_data();
    },
    form_clear() {
      console.log("点击了重置");

      this.tableObj.getdataListParm.parammaps.travelCode = "";
      this.tableObj.getdataListParm.parammaps.customerId = "";
      this.tableObj.getdataListParm.parammaps.customerName = "";
      this.tableObj.getdataListParm.parammaps.groupId = "";
      this.tableObj.getdataListParm.parammaps.statusName = "";
      this.tableObj.getdataListParm.parammaps.employeeId = "";

      this.tableObj.getdataListParm.parammaps.inputDatetime1 = "";
      this.tableObj.getdataListParm.parammaps.inputDatetime2 = "";
      this.tableObj.getdataListParm.parammaps.inputDatetime3 = "";

      this.tableObj.getdataListParm.parammaps.begainCreaterDate = "";
      this.tableObj.getdataListParm.parammaps.endCreaterDate = "";
      this.tableObj.getdataListParm.parammaps.beginPlanBeginDate = "";
      this.tableObj.getdataListParm.parammaps.endPlanBeginDate = "";
      this.tableObj.getdataListParm.parammaps.beginPlanSuccessDate = "";
      this.tableObj.getdataListParm.parammaps.endPlanSuccessDate = "";

      this.tableObj.getdataListParm.parammaps.beginServiceCost = "";
      this.tableObj.getdataListParm.parammaps.endServiceCost = "";

      this.tableObj.getdataListParm.offset = 1;
      this.get_table_data();
    },

    // 新增
    form_reset() {
      this.create.temp = {
        customerId: "",
        groupId: "",
        groupName: "",
        employeeId: "",
        inputDatetime2: "",
        planBeginDate: "",
        planSuccessDate: "",
        serviceCost: "",
        adress: "",
        reason: "",
        adress: "",
        remark: "",
        modifyName: "",
        id: "",
        userIds: "",
      };
    },
    //客户失去焦点
    customer_search_blur(item) {
      console.log("客户失去焦点");
      this.tableObj.getdataListParm.parammaps.customerId = "";
      this.tableObj.getdataListParm.parammaps.customerName = "";
      this.customerNameList = [];
    },

    //模糊查询客户
    customer_search(queryString, cb) {
      console.log("模糊查询输入值", queryString);
      GetDataByName({
        name: "getCustomerNameFuzzy",
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: "Map",
        parammaps: { inputvalue: queryString },
      }).then((response) => {
        this.customerNameList = response.data.list;
        console.log("客户名称下拉框", response);
        cb(response.data.list);
      });
    },

    //模糊查询客户选择
    change_customer_select(item) {
      console.log("客户名称模糊查询选中值", item);
      this.tableObj.getdataListParm.parammaps.customerId = item.id;
      this.tableObj.getdataListParm.parammaps.customerName = item.name;
    },

    //清空客户选择
    clear_customer_select(item) {
      document.activeElement.blur();
      this.tableObj.getdataListParm.parammaps.customerId = "";
      this.tableObj.getdataListParm.parammaps.customerName = "";
    },

    //监听 - 集团
    change_group(item) {
      console.log(item);
      console.log(this.create.temp.groupId);
      this.create.temp.groupId = item;
      this.create.getdataListParmCust.parammaps.groupId = item;

      this.create.temp.customerName = "";
      this.create.temp.customerId = "";
      this.create.customerNameList = [];

      this.get_customer_list();
      this.$forceUpdate();
    },
    // 弹窗中的客户
    get_customer_list() {
      GetDataByName(this.create.getdataListParmCust).then((response) => {
        if (response.data.list !== null) {
          this.create.customerNameList = response.data.list;
          console.log("弹窗中的客户数据", response.data.list);
        } else {
          this.create.customerNameList = [];
        }
      });
    },

    //监听 - 下拉中客户名称
    change_customer(item) {
      console.log(item);
      this.create.temp.customerId = item;

      this.create.temp.visitId = "";
      this.create.temp.telvisitId = "";
    },

    //监听 - 下拉中客户对接人
    changeReceiver(item) {
      this.create.temp.receiverName = this.create.receiverNameList.find(
        (obj) => obj.id === item
      ).name;
    },

    // 查看
    form_see(row) {
      this.create.temp.id = row.id;

      this.create.temp.userIds = row.userIds;

      console.log("点击了查看", row);

      this.create.temp = Object.assign({}, row);
      this.create.temp.inputDatetime2 = [
        row.planBeginDate,
        row.planSuccessDate,
      ];

      this.create.getdataListParmCust.parammaps.groupId = row.groupId;
      this.get_customer_list();

      this.create.dialogStatus = "see";
      this.create.dialogFormVisible = true;
    },

    // 通过
    form_adopt(row) {
      console.log("点击了通过", row);
      this.reset_adopt();

      this.adopt.temp.id = row.id;
      this.adopt.temp.contractStatus = row.contractStatus;
      this.adopt.dialogFormVisible = true;
      this.adopt.temp.statusName = row.statusName;
    },
    // 通过 - 重置
    reset_adopt() {
      this.adopt.temp.remark = "";
      this.adopt.temp.contractStatus = "";
      this.adopt.temp.statusName = "";
    },

    // 通过 - 确认
    form_adopt_save() {
      this.$refs["adopttemp"].validate((valid) => {
        if (valid) {
          var send_data = {
            common: { returnmap: "0" },
            data: [
              {
                name: "insertApproval",
                type: "e",
                parammaps: {
                  typeName: "出差审批",
                  objectId: this.adopt.temp.id,
                  statusId: "1",
                  remark: this.adopt.temp.remark,
                  userId: Cookies.get("employeid"),
                  stepName: this.adopt.temp.statusName,
                },
              },

              {
                name: "updateBusinessTravelSuccess",
                type: "e",
                parammaps: { id: this.adopt.temp.id },
              },
            ],
          };

          ExecDataByConfig(send_data).then((response) => {
            console.log("通过发送参数", send_data);
            if (response.msg !== "fail") {
              this.$notify({
                title: "成功",
                message: "通过成功",
                type: "success",
                duration: 2000,
              });
              this.adopt.dialogFormVisible = false;
              this.create.dialogFormVisible = false;

              this.get_table_data();

              var rowId = this.adopt.temp.id;
              var statusName = this.adopt.temp.statusName;

              if (statusName == "一审中") {
                this.get_wxPush(48, "出差", rowId);
              } else if (statusName == "二审中") {
                this.get_wxPush(49, "出差", rowId);
              } else if (statusName == "三审中") {
                this.get_wxPush(50, "出差", rowId);
              }

              if (this.isHome == "home") {
                // 返回首页
                this.$router.push({
                  name: "Dashboard",
                  params: { isTodo: "businessapp" },
                });
              }
            } else {
              this.$notify({
                title: "失败",
                message: "通过失败" + response.data,
                type: "error",
                duration: 2000,
              });
            }
          });
        }
      });
    },

    // 驳回
    form_reject(row) {
      console.log("点击了驳回", row);
      this.reset_reject();

      this.reject.temp.id = row.id;
      this.reject.temp.statusName = row.statusName;
      this.reject.temp.contractStatus = row.contractStatus;
      this.reject.dialogFormVisible = true;
    },
    // 驳回 - 重置
    reset_reject() {
      this.reject.temp.remark = "";
      this.reject.temp.contractStatus = "";
      this.reject.temp.statusName = "";
    },

    // 驳回 - 确认
    form_reject_save() {
      this.$refs["rejecttemp"].validate((valid) => {
        if (valid) {
          var send_data = {
            common: { returnmap: "0" },
            data: [
              {
                name: "insertApproval",
                type: "e",
                parammaps: {
                  typeName: "出差审批",
                  objectId: this.reject.temp.id,
                  statusId: "0",
                  remark: this.reject.temp.remark,
                  userId: Cookies.get("employeid"),
                  stepName: this.reject.temp.statusName,
                },
              },

              {
                name: "updateBusinessTravelFalse",
                type: "e",
                parammaps: { id: this.reject.temp.id },
              },
            ],
          };

          ExecDataByConfig(send_data).then((response) => {
            console.log("驳回发送参数", send_data);
            if (response.msg !== "fail") {
              this.$notify({
                title: "成功",
                message: "驳回成功",
                type: "success",
                duration: 2000,
              });
              this.reject.dialogFormVisible = false;
              this.create.dialogFormVisible = false;

              this.get_table_data();

              var rowId = this.reject.temp.id;
              var statusName = this.reject.temp.statusName;

              if (statusName == "一审中") {
                this.get_wxPush(51, "出差", rowId);
              } else if (statusName == "二审中") {
                this.get_wxPush(52, "出差", rowId);
              } else if (statusName == "三审中") {
                this.get_wxPush(53, "出差", rowId);
              }

              if (this.isHome == "home") {
                // 返回首页
                this.$router.push({
                  name: "Dashboard",
                  params: { isTodo: "businessapp" },
                });
              }
            } else {
              this.$notify({
                title: "失败",
                message: "驳回失败" + response.data,
                type: "error",
                duration: 2000,
              });
            }
          });
        }
      });
    },

    dialog_close() {
      this.create.dialogFormVisible = false;
      this.get_table_data();
      if (this.isHome == "home") {
        // 返回首页
        this.$router.push({
          name: "Dashboard",
          params: { isTodo: "businessapp" },
        });
      }
    },

    dialog_close_adopt() {
      this.adopt.dialogFormVisible = false;
      this.get_table_data();
      if (this.isHome == "home") {
        // 返回首页
        this.$router.push({
          name: "Dashboard",
          params: { isTodo: "businessapp" },
        });
      }
    },
    dialog_close_reject() {
      this.reject.dialogFormVisible = false;
      this.get_table_data();
      if (this.isHome == "home") {
        // 返回首页
        this.$router.push({
          name: "Dashboard",
          params: { isTodo: "businessapp" },
        });
      }
    },

    // 导出
    form_export(item) {
      if (item == 1) {
        console.log("点击了导出模板");
      } else {
        console.log("点击了导出数据");
      }
    },

    // 导入
    form_inport() {
      console.log("点击了导入");
    },
    //微信推送
    get_wxPush(remindId, remindTypeName, rowId) {
      var send_weixin_data1 = {
        name: "getRemindData",
        parammaps: {
          userId: Cookies.get("g_userId"),
          remindId: remindId,
          remindTypeName: remindTypeName,
          rowId: rowId,
        },
      };

      GetDataByName(send_weixin_data1).then((response) => {
        console.log("微信推送(获取参数)======>", response);
        if (response.data.message == "ok") {
          var receiverStr = response.data.list[0].receivers;
          var receiverArr = receiverStr.split(",");
          var value1 = response.data.list[0].value1;
          var value2 = response.data.list[0].value2;
          var value3 = response.data.list[0].value3;
          var value4 = response.data.list[0].value4;
          var send_weixin_data2 = {
            target: receiverArr,
            serviceId: remindId,
            content: [
              { color: "#173177", value: value1 },
              { color: "#173177", value: value2 },
              { color: "#173177", value: value3 },
              { color: "#173177", value: value4 },
            ],
          };

          wxpush(send_weixin_data2).then((response) => {
            console.log("微信推送(获取参数)======>", response);
          });
          // this.tableSumMoney = response.data.list[0].totlePrice
        } else {
          // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.search {
  padding-top: 10px;
  clear: both;
}
.table {
  margin-top: 10px;
}

/deep/ .el-input.is-disabled .el-input__inner {
  color: #000000 !important;
}
/deep/ .el-textarea.is-disabled .el-textarea__inner {
  color: #000000 !important;
}
/deep/ .el-radio__input.is-disabled + span.el-radio__label {
  color: #000000 !important;
}
/deep/ .el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000 !important;
}
</style>
