<template>
  <div class="app-container" v-loading="fullLoading">
    <card-table :modalData="projectList" labelWidth="120px" :searchParams="queryParams" @pagination="getList"
      :loading="loading" :tableSearch="true" @columnSearch="handleQuery" @resetList="resetQuery"
      @selection-change="handleSelectionChange" @sortChange="sortChange">
      <template #operations="{ selections }">
        <el-col :span="1.5">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['business:project:add']">{{ $t('project.addProject') }}</el-button>
        </el-col>
        <el-col :span="1.5" style="margin-left: 10px;">
          <el-button plain icon="el-icon-download" size="mini" @click="handleExport"
            v-hasPermi="['business:project:export']">{{ $t('common.export') }}</el-button>
        </el-col>
      </template>
      <template #default="{ list }">
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="No." type="index" width="50" align="center" fixed />
        <!-- 项目编码 -->
        <Column :label="$t('project.no')" prop="projectNo" :searchParams="queryParams" :showSearch="true" fixed
          sortable="custom">
          <template #default="{ row }">
            <span @click="handleView(row)" class="link-type">{{ row.projectNo }}</span>
          </template>
        </Column>
        <!-- 区域 -->
        <Column v-if="showAreaColumn" :label="$t('user.area')" prop="areaId" :searchParams="queryParams"
          :searchDict="areaList" :showSearch="true" valueProp="areaId" :labelProp="'areaName' + localLabelSuffix"
          searchType="select" selectMore width="200px" />
        <!-- 国家 -->
        <Column :label="$t('account.country')" prop="countryId" :searchParams="queryParams" :showSearch="true"
          valueProp="countryId" :labelProp="'countryName' + localLabelSuffix" searchType="select"
          :searchDict="countryList" select-more width="200px" />
        <!-- 城市 -->
        <Column :label="$t('project.city')" prop="city" :searchParams="queryParams" :showSearch="true" width="200px" />
        <!--所属代理商-->
        <Column :label="$t('lead.agent')" prop="ownerAgent" :showSearch="true" search-type="select"
          :searchParams="queryParams" :search-dict="agentList" select-more value-prop="agentId" label-prop="agentName"
          width="250px">
          <template #default="{ row }">
            <span>{{ row.ownerAgentName == 'common.head' ? $t(row.ownerAgentName) :
    row.ownerAgentName }}</span>
          </template>
        </Column>
        <!-- 项目名称 -->
        <Column :label="$t('project.name')" prop="projectName" :searchParams="queryParams" :showSearch="true"
          width="250px" />

        <!--设备数量-->
        <Column :label="$t('project.equipmentQuantity')" prop="equipmentQuantity" />
        <!--设备类型-->
        <Column :label="$t('project.equipmentType')" prop="equipmentType" />
        <!--金额-->
        <Column :label="$t('project.amount')" prop="amount" />

        <!-- 项目类型 -->
        <Column :label="$t('lead.segment')" prop="type" :searchParams="queryParams" :showSearch="true"
          searchType="select" :searchDict="dict.type.project_type" select-more width="200px" />
        <!-- 产品系列 -->
        <Column :label="$t('project.projectSegments')" prop="segmentedMarket" :searchParams="queryParams"
          :showSearch="true" searchType="select" :searchDict="dict.type.project_market" select-more
          :selectProp="queryParams.marketParam" width="200px" />
        <!-- 项目状态 -->
        <Column :label="$t('project.status')" prop="status" :searchParams="queryParams" :showSearch="true"
          searchType="select" :searchDict="dict.type.project_status" select-more :selectProp="queryParams.statusParam"
          width="250px">
          <template #default="{ row }">
            <ColorDictTag :bgc="statusColorMap[row.status].bgc"
              :label="formatDict(row.status, dict.type.project_status)"
              :label-color="statusColorMap[row.status].color" />
          </template>
        </Column>
        <!--项目进度-->
        <Column :label="$t('project.progress')" prop="progress" :searchParams="queryParams" :showSearch="true"
          searchType="select" :searchDict="dict.type.project_progress" select-more width="200px" />
        <!-- 标杆项目 -->
        <Column :label="$t('project.isModel')" prop="modelFlag" :searchParams="queryParams" :showSearch="true"
          searchType="select" :searchDict="dict.type.project_flag" width="200px" />
        <!-- 最新跟进结果 -->
        <Column :label="$t('account.followDesc')" prop="followDesc" width="250px" />
        <!-- 负责人 -->
        <Column :label="$t('lead.owner')" prop="ownerName" :searchParams="queryParams" :showSearch="true"
          width="200px" />


        <!--&lt;!&ndash; 计划成交月份 &ndash;&gt;-->
        <!--<Column :label="$t('account.planDealMonth')" prop="planDealMonth" width="200px" sortable="custom">-->
        <!--  <template #default="{ row }">-->
        <!--    <span>{{ row.planDealMonth ? getLocalTime(row.planDealMonth, 'YYYY-MM') : '-' }}</span>-->
        <!--  </template>-->
        <!--</Column>-->

        <!--&lt;!&ndash; 项目交期 &ndash;&gt;-->
        <!--<Column :label="$t('project.completionYear')" prop="completionYear" width="200px" sortable="custom">-->
        <!--  <template #default="{ row }">-->
        <!--    <span>{{ row.completionYear ? getLocalTime(row.completionYear, 'yyyy-MM-DD') : '-' }}</span>-->
        <!--  </template>-->
        <!--</Column>-->
        <!--&lt;!&ndash; 关联客户 &ndash;&gt;-->
        <!--<Column :label="$t('project.relatedCustomer')" prop="accountName" width="200px" />-->
        <!--&lt;!&ndash; 最新跟进时间 &ndash;&gt;-->
        <!--<Column :label="$t('account.followTime')" prop="followTime" width="250px">-->
        <!--  <template #default="{ row }">-->
        <!--    <span>{{ row.followTime ? getLocalTime(row.followTime, 'YYYY-MM-DD') : '-' }}</span>-->
        <!--  </template>-->
        <!--</Column>-->
        <!--&lt;!&ndash; 跟进人 &ndash;&gt;-->
        <!--<Column :label="$t('account.followPerson')" prop="followPerson" width="200px" />-->
        <!-- 操作 -->
        <Column :label="$t('common.operate')" :min-width="250" fixed="right" :showSearch="true" searchType="operate">
          <template #default="{ row }">
            <!--<el-button size="mini" type="text" icon="el-icon-view" @click="handleView(row)"
              v-hasPermi="['business:project:view']">{{ $t('common.view') }}</el-button>-->

            <el-button size="mini" type="text" icon="el-icon-edit" v-hasPermi="['business:project:edit']"
              v-if="canEdit(row)" @click="handleCommand('edit', row)">{{ $t('common.edit') }}</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" v-hasPermi="['business:project:remove']"
              v-if="canDelete(row)" @click="handleCommand('delete', row)">{{ $t('common.delete') }}</el-button>
            <el-button size="mini" type="text" icon="el-icon-right" v-if="canFollow(row)"
              v-hasPermi="['business:project:follow']" @click="handleCommand('follow', row)">{{ $t('project.follow')
              }}</el-button>
            <!-- 审批 -->
            <el-button size="mini" type="text" icon="el-icon-edit-outline" v-if="canApprove(row)"
              @click="handleCommand('approve', row)" v-hasPermi="['business:project:approve']">{{ $t('project.approve')
              }}</el-button>
            <el-dropdown @command="(command) => handleCommand(command, row)" style="margin-left:5px"
              v-if="canDelayLost(row) ||  canSetModel(row) || canCancelModel(row) || canChangeOwner(row)"
              v-hasPermi="[  'business:project:delayLost',  'business:project:setModel', 'business:project:cancelModel', 'business:project:changeOwner']">
              <el-button icon="el-icon-d-arrow-right" size="mini" type="text">
                {{ $t('common.more') }}</el-button>
              <el-dropdown-menu slot="dropdown">
                <!-- 延期丢单 -->
                <el-dropdown-item v-if="canDelayLost(row)" command="delayLost">
                  <el-button size="mini" type="text" icon="el-icon-edit"
                    v-hasPermi="['business:project:delayLost']">{{ $t('project.delayLost') }}</el-button>
                </el-dropdown-item>
                <!-- 设为标杆 -->
                <el-dropdown-item v-if="canSetModel(row)" command="setModel">
                  <el-button size="mini" type="text" icon="el-icon-s-flag"
                    v-hasPermi="['business:project:setModel']">{{ $t('project.setModel') }}</el-button>
                </el-dropdown-item>
                <!-- 设为非标杆 -->
                <el-dropdown-item v-if="canCancelModel(row)" command="cancelModel">
                  <el-button size="mini" type="text" icon="el-icon-s-flag"
                    v-hasPermi="['business:project:cancelModel']">{{ $t('project.cancelModel') }}</el-button>
                </el-dropdown-item>
                <!-- 更改负责人 -->
                <el-dropdown-item v-if="canChangeOwner(row)" command="changeOwner">
                  <el-button size="mini" type="text" icon="el-icon-edit"
                    v-hasPermi="['business:project:changeOwner']">{{ $t('project.changeOwner') }}</el-button>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </Column>
      </template>
    </card-table>

    <ProjectDialog ref="projectForm" :title="title" :visible="open" :type="type" :form="form"
      @closeDialog="closeDialog">
    </ProjectDialog>

    <el-dialog :title="$t('project.changeOwner')" :visible.sync="changeOwnerOpen" width="500px" append-to-body
      :before-close="cancelChangeOwner" :close-on-click-modal="false">
      <el-form ref="changeOwnerForm" :model="changeOwnerForm" :rules="changeOwnerRules" label-position="top">
        <el-form-item :label="$t('lead.owner')" prop="owner">
          <el-select v-model="changeOwnerForm.owner" clearable
            :placeholder="$t('common.pleaseSelect') + $t('lead.owner')" style="width: 300px;">
            <el-option v-for="item in ownerList" :key="item.userId" :label="item.nickName" :value="item.userId" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitChangeOwner" icon="el-icon-circle-check" :loading="confirmLoading">
          {{ $t('common.confirm') }}</el-button>
        <el-button @click="cancelChangeOwner" icon="el-icon-circle-check">{{ $t('common.cancel') }}</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="$t('project.delayLost')" :visible.sync="delayLostOpen" width="600px" append-to-body
      :before-close="cancelDelayLost" :close-on-click-modal="false">
      <el-form ref="delayLostForm" :model="delayLostForm" :rules="delayLostRules" label-position="top">
        <el-form-item :label="$t('project.delayLost')" prop="status">
          <el-radio-group v-model="delayLostForm.status">
            <el-radio label="09">{{ $t('project.delay') }}</el-radio>
            <el-radio label="10">{{ $t('project.lost') }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item :label="$t('project.reasonType')" prop="reasonType">
          <el-select v-model="delayLostForm.reasonType" clearable
            :placeholder="$t('common.pleaseSelect') + $t('project.reasonType')">
            <el-option v-for="dict in dict.type.project_reason_type" :key="dict.value" :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="delayLostForm.status == '09'" :label="$t('project.reason')" prop="reason">
          <el-input v-model="delayLostForm.delayRemark" type="textarea" maxlength="250" show-word-limit :rows="4"
            :placeholder="$t('common.pleaseInput') + $t('project.reason')"></el-input>
        </el-form-item>
        <el-form-item v-if="delayLostForm.status == '10'" :label="$t('project.reason')" prop="reason">
          <el-input v-model="delayLostForm.loseRemark" type="textarea" maxlength="250" show-word-limit :rows="4"
            :placeholder="$t('common.pleaseInput') + $t('project.reason')"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitDelayLost" icon="el-icon-circle-check" :loading="confirmLoading">
          {{ $t('common.confirm') }}</el-button>
        <el-button @click="cancelDelayLost" icon="el-icon-circle-check">{{ $t('common.cancel') }}</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="$t('project.approve')" :visible.sync="approveOpen" width="600px" append-to-body
      :before-close="cancelApprove" :close-on-click-modal="false">
      <el-form ref="approveForm" :model="approveForm" :rules="approveRules" label-position="top">
        <el-form-item :label="$t('project.approveStatus')" prop="status">
          <el-radio-group v-model="approveForm.status" @change="changeApproveStatus">
            <el-radio label="03">{{ $t('project.pass') }}</el-radio>
            <el-radio label="02">{{ $t('project.notPass') }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="approveForm.status === '02'" :label="$t('project.refuseReason')" prop="refuseReason">
          <el-input v-model="approveForm.refuseReason" type="textarea" maxlength="250" show-word-limit :rows="4"
            :placeholder="$t('common.pleaseInput') + $t('project.refuseReason')"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitApprove" icon="el-icon-circle-check" :loading="confirmLoading">
          {{ $t('common.confirm') }}</el-button>
        <el-button @click="cancelApprove" icon="el-icon-circle-check">{{ $t('common.cancel') }}</el-button>
      </div>
    </el-dialog>

    <FollowDialog ref="followDialog" @returnRow="getList"></FollowDialog>
  </div>
</template>

<script>
import { listProject, getProject, delProject, setModel, delayLost, approve, changeOwner } from "@/api/business/crm/project";
import { getAllAreaList } from "@/api/user/area";
import { getAllNationList } from "@/api/user/country";
import { selectForProject } from "@/api/user/agent";
import { getOwnerList } from "@/api/system/user";
import { getLocalTime } from "@/utils/data/dataUtils"
import ProjectDialog from "../project/dialog";
import FollowDialog from "@/views/crmManagement/follow/FollowDialog";
import ColorDictTag from "@/views/crmManagement/lead/ColorDictTag/index";
import { parseTime } from "@/utils/ruoyi";

const statusColorMap = {
  '01': {
    color: '#FFC500',
    bgc: 'rgba(255,200,12,0.12)'
  },
  '02': {
    color: '#D71943',
    bgc: '#FAEDED'
  },
  '03': {
    color: '#24CA5D',
    bgc: 'rgba(24,199,84,0.12)'
  },
  '09': {
    color: '#FC5821',
    bgc: 'rgba(252,88,33,0.12)'
  },
  '10': {
    color: '#FC5821',
    bgc: 'rgba(252,88,33,0.12)'
  },
}

// const labelSuffix = {
//   chinese: '',
//   english: 'US',
//   russia: 'RU',
//   spanish: 'ES',
// }

export default {
  name: "Project",
  dicts: ['project_flag', 'project_market', 'project_type', 'project_status', 'project_reason_type', 'project_progress'],
  components: { ProjectDialog, FollowDialog, ColorDictTag },
  data() {
    return {
      statusColorMap: statusColorMap,
      confirmLoading: false,
      fullLoading: false,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 项目表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        language: this.$i18n.locale,
        modelFlag: '',
        type: '',
        countryId: '',
        status: '',
        segmentedMarket: ''
      },
      // 表单参数
      form: {},
      areaList: [],
      countryList: [],
      agentList: [],
      type: "",
      language: null,
      ownerList: [],
      changeOwnerOpen: false,
      changeOwnerForm: {},
      changeOwnerRules: {
        owner: [
          { required: true, message: this.$t('common.pleaseSelect') + this.$t('project.owner'), trigger: "change" },
        ],
      },
      delayLostOpen: false,
      delayLostForm: {},
      delayLostRules: {
        status: [
          { required: true, message: this.$t('common.pleaseSelect') + this.$t('project.delayLost'), trigger: "blur" },
        ],
        reasonType: [
          { required: true, message: this.$t('common.pleaseSelect') + this.$t('project.reasonType'), trigger: "change" },
        ],
      },
      userInfo: {},
      approveOpen: false,
      approveForm: {},
      approveRules: {
        status: [
          { required: true, message: this.$t('common.pleaseSelect') + this.$t('project.approveStatus'), trigger: "blur" },
        ],
        refuseReason: [
          { required: true, message: this.$t('common.pleaseInput') + this.$t('project.refuseReason'), trigger: "blur" },
        ],
      }
    };
  },
  computed: {
    localLabelSuffix() {
      // return labelSuffix[this.$i18n.locale] || '';
      return localStorage.getItem('labelSuffix') || ''
    },

    showAreaColumn() {
      // VP 、总经理
      // const allowedRoles = ["sales_director", "manager"];
      // return allowedRoles.some(role => this.$store.getters.roles.includes(role));
      // 不可见的角色： 区总、销售经理、代理商经理、代理商销售、销售支持 暂不考虑多角色比如又是销售又是vp角色
      const invisibleRoles = ['area_sales_director', 'sales_manager', 'agent_manager', 'agent_sales', 'sales_support'];
      return !this.$store.getters.roles.some(role => invisibleRoles.includes(role));
    }
  },
  created() {
    this.language = this.$i18n.locale;
    this.userInfo = this.$store.state.user.userInfo;
    this.getList();
    this.getAreaList();
    this.getNationList();
    this.getAgentList();
    this.getOwnerList();

    this.listenRefreshListVuex();
  },
  methods: {
    parseTime,
    getLocalTime,
    handleCommand(command, row) {
      switch (command) {
        case "edit":
          this.handleUpdate(row)
          break;
        case "delete":
          this.handleDelete(row)
          break;
        case "approve":
          this.handleApprove(row)
          break;
        case "delayLost":
          this.handleDelayLost(row)
          break;
        case "follow":
          this.handleFollow(row)
          break;
        case "setModel":
          this.handleSetModel(row)
          break;
        case "cancelModel":
          this.handleCancelModel(row)
          break;
        case "changeOwner":
          this.handleChangeOwner(row)
          break;
      }
    },
    getAreaList() {
      getAllAreaList().then(res => {
        this.areaList = res.data;
      })
    },
    getOwnerList() {
      getOwnerList({onlySalesRole: true}).then(res => {
        this.ownerList = res.data;
      })
    },
    getAgentList() {
      selectForProject().then(res => {
        this.agentList = res.data;
        if (this.userInfo.deptId == 0) {
          this.agentList.unshift({ agentId: 0, agentName: this.$t('common.head') });
        }
      })
    },
    canApprove(row) {
      return row.status == '01' && this.userInfo.userId == row.parentSaleId
    },
    /** 当前项目是否可以编辑 */
    canEdit(row) {
      let flag = true;
      let permissionArray = this.userInfo.permissionChar.split(',');
      let rowPermissionArray = row.permissionChar.split(',');
      for (let i = 0; i < rowPermissionArray.length; i++) {
        if (!permissionArray.includes(rowPermissionArray[i])) {
          flag = false;
          break;
        }
      }
      return flag;
    },
    canDelete(row) {
      return (row.status == '01' || row.status == '02') && this.canEdit(row)
    },
    canDelayLost(row) {
      return row.status != '01' && row.status != '02' && row.status != '10' && this.canEdit(row)
    },
    canFollow(row) {
      return row.status != '01' && row.status != '02' && this.canEdit(row) 
    },
    canSetModel(row) {
      return row.modelFlag != '1' && row.status != '02' && row.status != '10' && this.canEdit(row)
    },
    canCancelModel(row) {
      return row.modelFlag != '0' && row.status != '02' && row.status != '10' && this.canEdit(row)
    },
    canChangeOwner(row) {
      return row.status != '02' && row.status != '10' && this.canEdit(row)
    },
    /** 获取所有国家列表 */
    getNationList() {
      getAllNationList().then(response => {
        this.countryList = response.data
      })
    },
    /** 获取字典数据匹配的值 */
    formatDict(value, dictData) {
      return dictData.find(dict => dict.value == value)?.label;
    },
    /** 查询项目列表 */
    getList() {
      this.loading = true;
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.queryParams.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        language: this.$i18n.locale,
        modelFlag: '',
        type: '',
        countryId: '',
        status: '',
        segmentedMarket: ''
      }
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.projectId)
      // this.single = selection.length !== 1
      // this.multiple = !selection.length
    },

    sortChange({ column, prop, order }) {
      if (order === 'ascending') {
        this.queryParams.orderByColumn = prop;
        this.queryParams.isAsc = 'asc';
      } else if (order === 'descending') {
        this.queryParams.orderByColumn = prop;
        this.queryParams.isAsc = 'desc';
      } else {
        this.queryParams.orderByColumn = null;
        this.queryParams.isAsc = null;
      }
      this.getList();
    },

    async setFormData(row) {
      this.fullLoading = true;
      await getProject(row.projectId).then(response => {
        this.form = response.data;
        this.form.accountId = this.form.accountId + "";
        this.$refs.projectForm.defaultData = [{
          accountId: response.data.accountId,
          accountNo: response.data.accountNo,
          accountName: response.data.accountName,
          areaId: response.data.areaId,
          countryId: response.data.countryId
        }]
        this.$refs.projectForm.myLeadList = this.form.leadList
        this.fullLoading = false;
        this.open = true;
      }).catch(() => {
        this.fullLoading = false;
      });
    },
    /** 更改负责人 */
    handleChangeOwner(row) {
      this.changeOwnerForm = {
        projectId: row.projectId,
        owner: row.owner,
        updateTime: row.updateTime
      }
      this.changeOwnerOpen = true;
    },
    cancelChangeOwner() {
      // this.resetForm("changeOwnerForm");
      this.changeOwnerOpen = false;
    },
    submitChangeOwner() {
      this.$refs["changeOwnerForm"].validate(valid => {
        if (valid) {
          this.confirmLoading = true;
          changeOwner(this.changeOwnerForm).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess(this.$t('common.editSuccess'));
              this.cancelChangeOwner();
              this.getList();
            } else {
              this.$modal.msgError(response.msg);
            }
          }).catch(() => { });
          this.confirmLoading = false;
        }
      });
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.$tab.openPage(this.$t('project.view'), '/project-view/' + row.projectId);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      if (this.$store.getters.userId != 1) {
        this.$set(this.form, 'owner', this.$store.getters.userId);
      }
      this.title = this.$t('project.addProject');
      this.type = 'add';
      this.open = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.title = this.$t('project.editProject');
      this.type = 'edit';
      this.setFormData(row);
    },
    closeDialog(e) {
      this.open = false;
      if (e) {
        this.getList();
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm(this.$t('common.isDelete')).then(() => {
        this.fullLoading = true;
        delProject(row.projectId).then(() => {
          this.getList();
          this.$modal.msgSuccess(this.$t('common.deleteSuccess'));
          this.fullLoading = false;
        })
      }).catch(() => { this.fullLoading = false; });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.queryParams.ids = this.ids;
      this.queryParams.language = this.$i18n.locale;
      let fileName = this.$t('index.guideFour') + parseTime(new Date(), '{y}{m}{d}') + '.xlsx'
      this.download('business/project/export', {
        ...this.queryParams
      }, fileName)
    },
    changeApproveStatus() {
      this.$set(this.approveForm, 'refuseReason', null);
    },
    /** 延期/丢单 */
    handleDelayLost(row) {
      this.delayLostForm = {
        projectId: row.projectId,
        updateTime: row.updateTime
      }
      this.delayLostOpen = true;
    },
    /** 设为标杆 */
    handleSetModel(row) {
      this.$modal.confirm(this.$t('project.confirmSetModel')).then(function () {
        return setModel({ projectId: row.projectId, modelFlag: '1', updateTime: row.updateTime });
      }).then((response) => {
        if (response.code == 200) {
          this.$modal.msgSuccess(this.$t('common.editSuccess'));
          this.getList();
        } else {
          this.$modal.msgError(response.msg);
        }
      }).catch(() => { });
    },
    /** 设为非标杆 */
    handleCancelModel(row) {
      this.$modal.confirm(this.$t('project.confirmCancelModel')).then(function () {
        return setModel({ projectId: row.projectId, modelFlag: '0', updateTime: row.updateTime });
      }).then((response) => {
        if (response.code == 200) {
          this.$modal.msgSuccess(this.$t('common.editSuccess'));
          this.getList();
        } else {
          this.$modal.msgError(response.msg);
        }
      }).catch(() => { });
    },
    cancelDelayLost() {
      this.$refs["delayLostForm"].resetFields();
      this.delayLostOpen = false;
    },
    /** 提交延期/丢单 */
    submitDelayLost() {
      this.$refs["delayLostForm"].validate(valid => {
        if (valid) {
          this.confirmLoading = true;
          if (this.delayLostForm.status == '09') {
            delete this.delayLostForm.loseRemark
          } else if (this.delayLostForm.status == '10') {
            delete this.delayLostForm.delayRemark
          }
          delayLost(this.delayLostForm).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess(this.$t('common.editSuccess'));
              this.cancelDelayLost();
              this.getList();
            } else {
              this.$modal.msgError(response.msg);
            }
          }).catch(() => { });
          this.confirmLoading = false;
        }
      });
    },
    /** 跟进 */
    handleFollow(row) {
      this.$refs.followDialog.dialogItemInit({ flag: '1', projectId: row.projectId })
    },
    /** 审批 */
    handleApprove(row) {
      this.approveForm = {
        projectId: row.projectId,
        updateTime: row.updateTime
      }
      this.approveOpen = true;
    },
    cancelApprove() {
      this.$refs["approveForm"].resetFields();
      this.approveOpen = false;
    },
    /** 提交审批 */
    submitApprove() {
      this.$refs["approveForm"].validate(valid => {
        if (valid) {
          this.confirmLoading = true;
          approve(this.approveForm).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess(this.$t('common.editSuccess'));
              this.cancelApprove();
              this.getList();
            } else {
              this.$modal.msgError(response.msg);
            }
          }).catch(() => { });
          this.confirmLoading = false;
        }
      });
    },

    /*  */
    listenRefreshListVuex() {
      this.$store.subscribe((mutation) => {
        if (mutation.type === 'refreshProject') {
          this.getList()
        }
      })
    },
  }
};
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
::v-deep .el-form-item--medium .el-form-item__label {
  line-height: 10px;
}
</style>
