<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="合同编号" prop="supplierContractCode">
        <el-input v-model="queryParams.supplierContractCode" placeholder="请输入合同编号" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="合同名称" prop="supplierContractName">
        <el-input v-model="queryParams.supplierContractName" placeholder="请输入合同名称" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="供应商" prop="supplierName">
        <el-input v-model="queryParams.supplierName" placeholder="请输入供应商" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="开始日期" prop="startDate">
        <el-date-picker v-model="queryParams.startDate" style="width: 250px" value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item label="结束日期" prop="endDate">
        <el-date-picker v-model="queryParams.endDate" style="width: 250px" value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item label="负责人" prop="ownerEmployeeName">
        <el-input v-model="queryParams.ownerEmployeeName" placeholder="负责人" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="contractStatus">
        <el-select v-model="queryParams.contractStatus" placeholder="请选择状态" style="width: 250px">
          <el-option label="未归档" value="0"></el-option>
          <el-option label="已归档" value="1"></el-option>
          <el-option label="已完成" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否关闭" prop="closed">
        <el-select v-model="queryParams.closed" placeholder="请选择是否关闭" style="width: 250px">
          <el-option label="否" value="0"></el-option>
          <el-option label="是" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否终止" prop="terminate">
        <el-select v-model="queryParams.terminate" placeholder="请选择是否终止" style="width: 250px">
          <el-option label="否" value="0"></el-option>
          <el-option label="是" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['contract:supplier:create']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
          v-hasPermi="['contract:supplier:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
                <el-button type="success" size="mini" :disabled="single" @click="handleOpen()"
                    v-hasPermi="['contract:supplier:open']">开启</el-button>
            </el-col>
      <el-col :span="1.5">
                <el-button type="info" size="mini" :disabled="single" @click="handleReceive('关闭')"
                    v-hasPermi="['contract:supplier:close']">关闭</el-button>
            </el-col>
            
            <el-col :span="1.5">
                <el-button type="danger" size="mini" :disabled="single" @click="handleReceive('终止')"
                    v-hasPermi="['contract:supplier:terminate']">终止</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button icon="el-icon-plus" size="mini" :disabled="single" @click="handleReceive('修改')"
                    v-hasPermi="['contract:supplier:status']">修改合同状态</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button icon="el-icon-plus" size="mini" :disabled="single" @click="handleAlter()"
                    v-hasPermi="['contract:supplier:alter']">变更</el-button>
            </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align="center" width="55" />
      <el-table-column label="合同编号" align="center" prop="supplierContractCode" min-width="350">
      <template v-slot="scope">
          <router-link :to="'/finance/contract/supplier/historyData/' + scope.row.supplierContractCode" class="link-type">
            <span>{{ scope.row.supplierContractCode }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="合同名称" align="center" prop="supplierContractName" min-width="150" />
      <el-table-column label="是否框架合同" align="center" prop="isFrameContractDesc" min-width="100" />
      <el-table-column label="供应商" align="center" prop="supplierName" min-width="150" />
      <el-table-column label="合同开始日期" align="center" prop="startDate" min-width="100" />
      <el-table-column label="合同结束日期" align="center" prop="endDate" min-width="100" />
      <el-table-column label="合同金额" align="center" prop="money" min-width="100" />
      <el-table-column label="负责人" align="center" prop="ownerEmployeeName" min-width="100" />
      <el-table-column label="所属部门" align="center" prop="deptName" min-width="100"/>

      <el-table-column label="状态" align="center" prop="contractStatusDesc" min-width="100"/>
      <el-table-column label="是否关闭" align="center" prop="closedDesc" min-width="100"/>
      <el-table-column label="是否终止" align="center" prop="terminateDesc" min-width="100"/>

      <el-table-column label="创建人" align="center" prop="creatorName" min-width="100" />
      <el-table-column label="创建时间" align="center" prop="createTime" min-width="150">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" min-width="150">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['contract:supplier:update']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['contract:supplier:delete']">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-detail" @click="handleDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="合同编号" prop="supplierContractCode">
              <el-input v-model="form.supplierContractCode" placeholder='请输入合同名称' disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="合同名称" prop="supplierContractName">
              <el-input maxlength="30" v-model="form.supplierContractName" placeholder='请输入合同名称'></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="框架合同" prop="isFrameContract">
              <el-select v-model="form.isFrameContract" placeholder="请选择是否框架合同" style="width: 100%">
                <el-option label="否" :value="parseInt(0)"></el-option>
                <el-option label="是" :value="parseInt(1)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="供应商" prop="supplierName">
              <el-input maxlength="30" v-model="form.supplierName" placeholder='请输入供应商'></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="开始日期" prop="startDate">
              <el-date-picker value-format="yyyy-MM-dd" v-model="form.startDate" type="date" placeholder="选择日期"
                style="width: 100%;">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="结束日期" prop="endDate">
              <el-date-picker value-format="yyyy-MM-dd" v-model="form.endDate" type="date" placeholder="选择日期"
                style="width: 100%;">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="合同金额" prop="money">
              <el-input v-model="form.money" placeholder='请输入合同金额(元)'
                oninput="value=value.match(/\d+\.?\d{0,2}/,'')"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="负责人" prop="ownerEmployeeName">
              <el-input v-model="form.ownerEmployeeName" placeholder='点击选择' readonly
                @click.native="openSingle"></el-input>
            </el-form-item>
          </el-col>
            <el-col :span="12" style="display: none;">
              <el-form-item label="负责人Id" style="display: none;">
                <el-input v-model="form.ownerEmployeeId" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="所属部门" prop="deptName">
                <el-input v-model="form.deptName" placeholder='所属部门' disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="附件">
                <el-upload :action="fileUrl" :headers="headers" :file-list="files" :on-success="handleFileSuccessCite"
                  :before-upload="beforeUploadFile" :on-remove="handleRemove">
                  <el-button size="small" type="primary">点击上传</el-button>
                </el-upload>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注">
                <el-input maxlength="200" rows="4" show-word-limit type="textarea" v-model="form.remarks"
                  placeholder="请输入" />
              </el-form-item>
            </el-col>
          </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 详情对话框 -->
    <el-dialog :title="title" :visible.sync="openDetail" width="800px" append-to-body>
      <div class="widget-wrapper">
        <div class="widget-list">
          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <span class="field-required">*</span>
              <div class="field-name">合同编号</div>
            </div>
            <div class="field-component">
              <span :title="form.supplierContractCode">{{ form.supplierContractCode }}</span>
            </div>
          </div>
          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <span class="field-required">*</span>
              <div class="field-name">合同名称</div>
            </div>
            <div class="field-component">
              <span :title="form.supplierContractName">{{ form.supplierContractName }}</span>
            </div>
          </div>
          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <span class="field-required">*</span>
              <div class="field-name">框架合同</div>
            </div>
            <div class="field-component">
              <span :title="form.isFrameContractDesc">{{ form.isFrameContractDesc }}</span>
            </div>
          </div>
          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <span class="field-required">*</span>
              <div class="field-name">供应商</div>
            </div>
            <div class="field-component">
              <span :title="form.supplierName">{{ form.supplierName }}</span>
            </div>
          </div>


          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <span class="field-required">*</span>
              <div class="field-name">开始日期</div>
            </div>
            <div class="field-component">
              <span :title="form.startDate">{{ form.startDate }}</span>
            </div>
          </div>
          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <span class="field-required">*</span>
              <div class="field-name">结束日期</div>
            </div>
            <div class="field-component">
              <span :title="form.endDate">{{ form.endDate }}</span>
            </div>
          </div>

          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <span class="field-required">*</span>
              <div class="field-name">合同金额</div>
            </div>
            <div class="field-component">
              <span :title="form.money">{{ form.money }}</span>
            </div>
          </div>
          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <span class="field-required">*</span>
              <div class="field-name">负责人</div>
            </div>
            <div class="field-component">
              <span :title="form.ownerEmployeeName">{{ form.ownerEmployeeName }}</span>
            </div>
          </div>
          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <div class="field-name">所属部门</div>
            </div>
            <div class="field-component">
              <span :title="form.deptName">{{ form.deptName }}</span>
            </div>
          </div>

          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <div class="field-name">附件</div>
            </div>
            <div class="field-component">
              <div v-for="(item, index) in form.fileList" :key="index">
                <a :href="item.url" target="_blank" :title="item.name" style="color: #5094d5;">{{ item.name }}</a>
              </div>
            </div>

          </div>
          <div class="fx-field x-grid-col-12">
            <div class="field-label">
              <div class="field-name">备注</div>
            </div>
            <div class="field-component">
              <span :title="form.remarks">{{ form.remarks }}</span>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
     <!-- 领用,归还,报废对话框 -->
     <el-dialog :title="receiveTitle+'合同'" :visible.sync="openReceive" width="600px" append-to-body>
            <el-form ref="receiveform" :model="receiveform" :rules="receiveRules" label-width="80px">
                <el-row>
                   
                   
                   
                   

                    <el-col :span="24" v-if="receiveTitle=='修改'">
                      <el-form-item label="合同状态" prop="contractStatus">
                        <el-select v-model="receiveform.contractStatus" placeholder="请选择状态" style="width: 100%">
                          <el-option label="未归档" value="0"></el-option>
                          <el-option label="已归档" value="1"></el-option>
                          <el-option label="已完成" value="2"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24" v-if="receiveTitle=='关闭'">
                        <el-form-item label="关闭原因" prop="closeReason">
                            <el-input maxlength="200" rows="4" show-word-limit type="textarea" v-model="receiveform.closeReason"
                                placeholder="请输入" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" v-if="receiveTitle=='终止'">
                        <el-form-item label="终止日期" prop="terminateDate">
                            <el-date-picker value-format="yyyy-MM-dd" v-model="receiveform.terminateDate" type="date"
                                placeholder="选择报废日期" style="width: 100%;">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" v-if="receiveTitle=='终止'">
                        <el-form-item label="终止原因" prop="terminateReason">
                            <el-input maxlength="200" rows="4" show-word-limit type="textarea" v-model="receiveform.terminateReason"
                                placeholder="请输入" />
                        </el-form-item>
                    </el-col>
                </el-row>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitReceiveForm">确 定</el-button>
                <el-button @click="cancelReceive">取 消</el-button>
            </div>
        </el-dialog>
    <PeopleSelect ref="peopleSelect" type="single" :isCheck="true" :open="singlePeopleOpen"
      @cancel="singlePeopleOpen = false" @submit="submitSingle"></PeopleSelect>
  </div>
</template>

<script>
import { open,close,terminate,editSupplierStatus,alter, getSupplierContractCode, listSupplier, getSupplier, delSupplier, addSupplier, updateSupplier, exportSupplier } from "@/api/finance/contract/supplier";
import { getBaseHeader } from "@/utils/request";
import PeopleSelect from "@/components/PeopleSelect/index.vue";
import { getEmployeeInfo } from "@/api/system/user";
export default {
  components: {
    PeopleSelect,
  },
  data() {
    return {
      receiveTitle:'',
      openReceive: false,
      dataInfo:undefined,
      // 非单个禁用
      single: true,
      singlePeopleOpen:false,
      files: [],
      // 设置上传的请求头部
      headers: getBaseHeader(),
      // 上传的地址
      fileUrl: process.env.VUE_APP_BASE_API + '/admin-api/infra/file/uploaData',
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openDetail: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        supplierContractCode: undefined,
        supplierContractName: undefined,
        
        supplierName: undefined,
        startDate: [],
        endDate: [],
        ownerEmployeeName: undefined,
        contractStatus: undefined,
        closed:undefined,
        terminate:undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        supplierContractCode: [
          { required: true, message: '请输入合同编号', trigger: 'blur' },
        ],
        supplierContractName: [
          { required: true, message: '请输入合同名称', trigger: 'blur' },
        ],
        isFrameContract: [
          { required: true, message: '请选择是否框架合同', trigger: 'blur' }
        ],
        supplierName: [
          { required: true, message: '请选择供应商', trigger: 'blur' }
        ],
        startDate: [
          { required: true, message: '请选择开始日期', trigger: 'blur' }
        ],
        endDate: [
          { required: true, message: '请选择结束日期', trigger: 'blur' }
        ],
        money: [
          { required: true, message: '请输入金额', trigger: 'blur' },
          {
            pattern: /^(([1-9]{1}\d{0,9})|(0{1}))(\.\d{1,2})?$/,
            message: "请输入合法的金额数字，最多两位小数",
            trigger: "blur"
          }
        ],
        ownerEmployeeName: [
          { required: true, message: '请选择负责人', trigger: 'change' },
        ],
      },
      receiveform:{},
            receiveRules: {
              contractStatus: [
                    { required: true, message: "请选合同状态", trigger: 'change' }
                ],
                
               
               
                closeReason: [
                    { required: true, message: '请输入原因', trigger: 'blur' },
                ],
                terminateDate: [
                    { required: true, message: '请选择日期', trigger: 'change' }
                ],
                terminateReason: [
                    { required: true, message: '请输入原因', trigger: 'blur' },
                ],
                
                

            },
    };
  },
  created() {
    this.getList();
    this.getListSimpleSupplier();
  },
  methods: {
     //打开关闭，终止，修改合同状态弹窗
     handleReceive(val) {
            this.reset();
            if((val == '关闭' || val == '终止' || val == '变更') && this.dataInfo[0].closed == 0){
                this.receiveTitle = val;
                this.openReceive = true;
            }
            else if(val == '修改'){
                this.receiveform.employeeName = this.dataInfo[0].receiveEmployeeName;
                this.receiveTitle = val;
                this.openReceive = true;
                
            }else{
                this.$message.warning("该合同已关闭不支持此操作,请重新选择!");
                return;
            }
            
            
        },
    handleOpen(){
      if(this.dataInfo[0].closed==1){
        open({id:this.dataInfo[0].id}).then(response => {
          this.$modal.msgSuccess("开启成功");
          this.getList();
        });
      }else{
        this.$message.warning("该合同已开启不支持此操作,请重新选择!");
        return;
      }
      
      
      
    },

    handleAlter(){
      if(this.dataInfo[0].closed==0){
        this.reset();
        const id = this.dataInfo[0].id;
        getSupplier(id).then(response => {
          this.files = [];
          this.form = response.data;
          this.open = true;
          this.title = "变更";
        });
      }else{
        this.$message.warning("该合同已开启不支持此操作,请重新选择!");
        return;
      }
      
    },
    handleSelectionChange(selection) {
            console.log(selection);
            this.dataInfo = selection.map(item => item)
            console.log(this.dataInfo);
            this.single = selection.length != 1
        },
    getUser() {
        let userInfo = JSON.parse(this.$store.getters.userInfo);
        this.form.ownerEmployeeName = userInfo.nickname;
        this.form.ownerEmployeeId = userInfo.id;
        this.form.deptName = userInfo.deptName;
    },
    getEmployee() {
      getEmployeeInfo(this.form.ownerEmployeeId).then(response => {
        let employeeInfo = response.data;
        this.form.deptName = employeeInfo.deptName;
        // this.form.position = employeeInfo.position;
        // this.form.employeePhone = employeeInfo.phone;
        // this.form.entryDate = employeeInfo.entryDate;
        // this.form.probationEndDate = employeeInfo.probationEndDate;
      });
    },
     //打开选人弹窗
     openSingle() {
      this.singlePeopleOpen = true;
    },
    submitSingle(userNamelist, nikeNamelist, userIdList) {
      console.log(userNamelist);
      this.form.ownerEmployeeName = nikeNamelist.join();
      this.form.ownerEmployeeId = userIdList.join();
      this.getEmployee();
      this.singlePeopleOpen = false;
    },

    getSupplierContractCode() {
      getSupplierContractCode().then(response => {
        this.form.supplierContractCode = response.data;
      });
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
      let fileIds = [];
      for (let i in fileList) {
        let id = fileList[i].response.data.id;
        fileIds.push(id);
      }
      this.form.fileIdList = fileIds;
    },
    beforeUploadFile(file) {
      console.log(file);
      const size = file.size / 1024 / 1024;
      console.log(size);
      if (size > 5) {
        this.$message.error("文件大小不能超过5MB！");
        return false;
      }
    },
    handleFileSuccessCite(res, file, fileList) {
      console.log(file, fileList);
      console.log("------", "==========");
      console.log("res = ", res);

      let fileIds = [];
      for (let i in fileList) {
        let response = fileList[i].response;
        if (response.errno && response.errno != "0") {
          this.$message.error("该文件上传失败,已被移除,请重新上传!");
          // 上传失败移除该 file 对象
          fileList.splice(i, 1);
        } else {
          let id = fileList[i].response.data.id;
          fileIds.push(id);
        }
      }
      this.form.fileIdList = fileIds;
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      listSupplier(this.queryParams).then(response => {
        this.dataList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelReceive() {
            this.openReceive = false;
            this.reset();
        },
    // 表单重置
    reset() {
      this.files = [],
      this.form = {
        supplierContractCode: undefined,
        supplierContractName: undefined,
        isFrameContract: undefined,
        supplierName: undefined,
        startDate: undefined,
        endDate: undefined,
        money: undefined,


        ownerEmployeeName: undefined,
        ownerEmployeeId: undefined,
        deptName: undefined,
        fileIdList: undefined,
        remarks: undefined,
      };
      this.receiveform = {
        id: undefined,
        contractStatus: undefined,
        closeReason: undefined,
        terminateDate: undefined,
        terminateReason: undefined,
              
      };
      this.resetForm("form");
      this.resetForm("receiveform");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getSupplierContractCode();
      this.getUser();
      this.open = true;
      this.title = "添加";
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id;
      getSupplier(id).then(response => {
        this.form = response.data;
        this.openDetail = true;
        this.title = "详情";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getSupplier(id).then(response => {
        let files = response.data.fileList;
        if (files) {
          this.files = [];
          for (let i in files) {
            let url = files[i].url;
            let name = files[i].name;
            let id = files[i].id;

            this.files.push({
              name: name,
              url: url,
              response: { error: "0", data: { url: url, id: id } },
            });
          }
        }
        this.form = response.data;
        this.open = true;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.title == '变更'){
            alter(this.form).then(response => {
              this.$modal.msgSuccess("变更成功");
              this.open = false;
              this.getList();
            });
          }
          else if (this.form.id !== undefined) {
            updateSupplier(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSupplier(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    submitReceiveForm: function () {
            this.$refs["receiveform"].validate(valid => {
                if (valid) {
                    this.receiveform.id = this.dataInfo[0].id;
                    if (this.receiveTitle== '关闭') {
                        close(this.receiveform).then(response => {
                            this.$modal.msgSuccess("关闭成功");
                            this.openReceive = false;
                            this.getList();
                        });
                    } else if(this.receiveTitle== '终止') {
                      terminate(this.receiveform).then(response => {
                            this.$modal.msgSuccess("终止成功");
                            this.openReceive = false;
                            this.getList();
                        });
                    }else{
                      editSupplierStatus(this.receiveform).then(response => {
                            this.$modal.msgSuccess("修改合同状态成功");
                            this.openReceive = false;
                            this.getList();
                        });
                    }
                }
            });
        },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据项?').then(function () {
        return delSupplier(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      // 执行导出
      this.$modal.confirm('是否确认导出所有数据项?').then(() => {
        this.exportLoading = true;
        return exportSupplier(params);
      }).then(response => {
        this.$download.excel(response, '采购合同信息.xls');
        this.exportLoading = false;
      }).catch(() => { });
    }
  }
};
</script>
<style lang="scss" scoped>
.widget-wrapper>.widget-list {
  display: flex;
  flex-wrap: wrap;
}

.x-grid-col-6 {
  width: 50%;
}

.x-grid-col-12 {
  width: 100%;
}

.fx-field {
  line-height: 20px;
  padding: 7px 12px 12px;
  position: relative;
}

.fx-field .field-label {
  word-wrap: break-word;
  color: #141e31;
  display: flex;
  font-weight: 600;
  line-height: 20px;
  padding: 5px 0;
  position: relative;
  word-break: break-word;
}

.fx-field .field-label .field-required {
  color: #eb5050;
  margin-left: -6px;
  position: relative;
}

.fx-field .field-label .field-name {
  overflow: hidden;
}

.field-component {
  word-wrap: break-word;
  background: #f5f6f8;
  border-radius: 2px;
  color: #141e31;
  font-size: 14px;
  line-height: 20px;
  min-height: 32px;
  padding: 6px 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

ul {
  padding-left: 0px !important;
}

.el-tag+.el-tag {
  margin-left: 10px;
}
</style>