<template>
  <div class="app-container">
    <el-card style="height: 850px;padding: 0">
      <el-tabs v-model="PartType" type="border-card" @tab-click="pageCurrent=1;pageCurrent1=1;getData()">
        <el-tab-pane label="物料采购" name="物料采购">
          <el-row>
            <div style="margin-top: 7px; margin-bottom: 7px">
              <el-select v-model="orderNumberValue" style="width:180px;" placeholder="订单号" size="small" filterable clearable @change="getproductpartName();searchTable();">
                <el-option
                  v-for="item in orderNumber"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
              <el-select v-model="productNameValue" style="width:150px" placeholder="产品名称" size="small" filterable clearable @change="searchTable()">
                <el-option
                  v-for="item in productName"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
              <el-input v-model="purchasedPartsValue" style="width:150px" placeholder="采购件" size="small" clearable @keyup.enter.native="searchTable()"/>
              <el-button type="warning" plain icon="el-icon-plus" size="small" @click="purchaseContract">采购合同</el-button>
              <el-checkbox v-show="Number(token)===2" v-model="checked" style="margin-left: 50px" @change="searchTable()">已隐藏</el-checkbox>
              <el-button type="primary" plain icon="el-icon-sort" size="small" style="margin-left:700px" @click="changeMaterial">变更物料</el-button>
              <el-badge :value="numberReturnedItems" class="item">
                <el-button type="text" size="small" @click="viewReturnedContracts()">退货通知</el-button>
              </el-badge>
              <!--          <el-button type="success" plain icon="el-icon-download" size="small" style="margin-left: 760px" @click="exportExcel()">导出</el-button>-->
            </div>
            <el-table v-loading="loading" :data="tableData" highlight-current-row border size="mini" style="width:1661px; margin-top: 10px" height="380" @sort-change="sortChange" @row-click="getMaterial">
              <el-table-column width="55px" label="选入" align="center">
                <template slot-scope="scope">
                  <el-button :disabled="Number(scope.row.是否确认) === 0 || checked" type="text" icon="el-icon-bottom" size="mini" @click="selectIn(scope.row)"/>
                </template>
              </el-table-column>
              <el-table-column width="189px" sortable="采购件" label="采购件" align="center" prop="采购件">
                <template slot-scope="scope">
                  {{ scope.row.采购件 }}
                </template>
              </el-table-column>
              <el-table-column width="145px" label="图号/型号" align="center" prop="">
                <template slot-scope="scope">
                  {{ scope.row.图号或型号 }}
                </template>
              </el-table-column>
              <el-table-column width="55px" label="数量" align="center" prop="">
                <template slot-scope="scope">
                  {{ scope.row.数量 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('材料')" label="材料" align="center" prop="">
                <template slot-scope="scope">
                  {{ scope.row.材料 }}
                </template>
              </el-table-column>
              <el-table-column width="65px" label="收货人" align="center" prop="">
                <template slot-scope="scope">
                  {{ scope.row.收货人 }}
                </template>
              </el-table-column>
              <el-table-column width="143px" sortable="订单编号" label="订单编号" align="center" prop="订单编号">
                <template slot-scope="scope">
                  {{ scope.row.订单编号 }}
                </template>
              </el-table-column>
              <el-table-column width="130px" sortable="产品名称" label="产品名称" align="center" prop="产品名称">
                <template slot-scope="scope">
                  {{ scope.row.产品名称 }}
                </template>
              </el-table-column>
              <el-table-column label="产品详情" align="center">
                <template slot-scope="scope">
                  {{ scope.row.产品详情 }}
                </template>
              </el-table-column>
              <el-table-column width="120px" label="订单备注" align="center">
                <template slot-scope="scope">
                  {{ scope.row.订单备注 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('日期')" label="采购期限" align="center">
                <template slot-scope="scope">
                  {{ scope.row.采购期限 }}
                </template>
              </el-table-column>
              <el-table-column width="55px" label="库存" align="center">
                <template slot-scope="scope">
                  {{ scope.row.累计库存 }}
                </template>
              </el-table-column>
              <el-table-column width="100px" label="物料备注" align="center" prop="">
                <template slot-scope="scope">
                  {{ scope.row.物料备注 }}
                </template>
              </el-table-column>
              <el-table-column v-show="Number(token)===2" width="185px" label="操作" align="center">
                <template slot-scope="scope">
                  <el-tooltip :open-delay="700" effect="dark" content="图纸" placement="top">
                    <el-button :disabled="scope.row.图纸 === null" type="text" icon="el-icon-search" size="mini" @click="getNum(scope.row)">图纸</el-button>
                  </el-tooltip>
                  <el-tooltip :open-delay="700" effect="dark" content="使用库存" placement="top">
                    <el-button :disabled="Number(scope.row.累计库存) < Number(scope.row.数量)" type="text" size="mini" @click="useInventory(scope.row)">使用库存</el-button>
                  </el-tooltip>
                  <el-tooltip :open-delay="700" effect="dark" content="隐藏" placement="top">
                    <el-button v-show="!checked" type="text" size="mini" @click="Disappear(scope.row)">隐藏</el-button>
                  </el-tooltip>
                  <el-tooltip :open-delay="700" effect="dark" content="恢复" placement="top">
                    <el-button v-show="checked" type="text" size="mini" style="margin-right: 5px" @click="Recovery(scope.row)">恢复</el-button>
                  </el-tooltip>
                </template>
              </el-table-column>
            </el-table>

            <el-col style="width: 621px">
              <!--        <el-card>-->
              <div style="margin-top: 10px">
                <el-table v-loading="loading" :data="tableData1" :header-cell-style="{background: '#2283D4',color: 'white'}" highlight-current-row border stripe size="mini" style="width: 621px;margin-top: 10px" height="320" @row-click="searchTable2">
                  <el-table-column width="120px" label="采购合同号" align="center" prop="" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{ scope.row.采购合同号 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="120px" label="供应商" show-overflow-tooltip align="center">
                    <template slot-scope="scope">
                      {{ scope.row.供应商 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="120px" label="未过原因" show-overflow-tooltip align="center">
                    <template slot-scope="scope">
                      {{ scope.row.未通过原因 }}
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                      <el-tooltip :open-delay="700" effect="dark" content="提交" placement="top">
                        <el-button type="text" icon="el-icon-check" size="mini" @click="Submit(scope.row)">提交</el-button>
                      </el-tooltip>
                      <el-tooltip :open-delay="700" effect="dark" content="合同" placement="top">
                        <el-button type="text" icon="el-icon-printer" size="mini" style="margin-right: 5px" @click="contract(scope.row)">合同</el-button>
                      </el-tooltip>
                      <el-tooltip :open-delay="700" effect="dark" content="上传图片" placement="top">
                        <el-button size="mini" type="text" icon="el-icon-circle-plus-outline" @click="updatePicture(scope.row)">图片</el-button>
                      </el-tooltip>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <!--            </el-card>-->
            </el-col>

            <el-col style="margin-left: 10px;width: 1021px">
              <!--            <el-card>-->
              <div style="margin-top: 10px">
                <el-table
                  v-loading="loading"
                  ref="table"
                  :data="tableData2"
                  :header-cell-style="{background: '#19466E',color: 'white'}"
                  :summary-method="getSummaries"
                  highlight-current-row
                  show-summary
                  border
                  stripe
                  size="mini"
                  style="width: 1021px;margin-top: 10px;margin-bottom: 500px"
                  height="320">
                  <el-table-column width="60px" label="选出" align="center">
                    <template slot-scope="scope">
                      <el-button type="text" icon="el-icon-top" size="mini" @click="selectOut(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column width="170px" label="采购件" align="center" prop="">
                    <template slot-scope="scope">
                      {{ scope.row.采购件 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('图号')" label="图号/型号" align="center" prop="">
                    <template slot-scope="scope">
                      {{ scope.row.图号或型号 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('材料')" label="材料" align="center" prop="">
                    <template slot-scope="scope">
                      {{ scope.row.材料 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="90px" label="数量" align="center" prop="数量">
                    <template slot-scope="scope">
                      <!--                      {{ scope.row.数量 }}-->
                      <el-input v-model="scope.row.数量" size="mini" type="number" style="margin: 0;width: 100%" @change="updateProcess(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('单位')" label="单位" align="center" prop="">
                    <template slot-scope="scope">
                      {{ scope.row.单位 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="130px" label="单价（元）" align="center" prop="单价" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.单价" size="mini" type="number" style="margin: 0;width: 100%" @change="updateProcess(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column width="110px" label="金额（元）" align="center" prop="">
                    <template slot-scope="scope">
                      {{ (scope.row.数量 * scope.row.单价).toFixed(2) }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('备注')" label="采购备注" align="center" prop="">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.采购备注" size="mini" style="margin: 0;width: 100%" @change="updateProcess(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                      <el-tooltip :open-delay="700" effect="dark" content="操作" placement="top">
                        <el-button :disabled="numberPart === ''" type="text" size="mini" @click="printDrawings(scope.row)">图纸</el-button>
                      </el-tooltip>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <!--            </el-card>-->
            </el-col>
          </el-row>
        </el-tab-pane>

        <el-tab-pane label="耗材采购" name="耗材采购">
          <el-row>
            <el-col style="margin-left: 7px;width: 351px">
              <!--        <el-card>-->
              <div style="margin-top: 7px; margin-bottom: 7px">
                <el-input v-model="contractValue" style="width:150px;margin-left: 7px" placeholder="合同号" size="small" clearable @keyup.enter.native="searchTable5()"/>
                <el-button type="warning" plain icon="el-icon-plus" size="small" style="margin-left:30px" @click="consumablesProcurement">耗材采购</el-button>
                <!--          <el-button type="success" plain icon="el-icon-download" size="small" style="margin-left: 760px" @click="exportExcel()">导出</el-button>-->
              </div>
              <div style="margin-top: 10px">
                <el-table v-loading="loading" :data="tableData3" highlight-current-row border stripe size="mini" style="width: 351px;margin-top: 10px" height="730" @row-click="searchTable6">
                  <el-table-column width="120px" label="采购合同号" align="center" prop="" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{ scope.row.采购合同号 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('供应商')" label="供应商" align="center" show-overflow-tooltip prop="">
                    <template slot-scope="scope">
                      {{ scope.row.供应商 }}
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                      <el-tooltip :open-delay="700" effect="dark" content="提交" placement="top">
                        <el-button type="text" icon="el-icon-check" size="mini" style="margin-right: 5px" @click="Submit1(scope.row)">提交</el-button>
                      </el-tooltip>
                      <el-tooltip :open-delay="700" effect="dark" content="合同" placement="top">
                        <el-button type="text" icon="el-icon-printer" size="mini" style="margin-right: 5px" @click="contract(scope.row)"/>
                      </el-tooltip>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <!--            </el-card>-->
            </el-col>

            <el-col style="margin-left: 30px;width: 931px">
              <!--            <el-card>-->
              <div style="margin-top: 7px; margin-bottom: 7px">
                <span>名称：</span>
                <el-input v-model="materialName1" placeholder="名称" style="width: 170px" size="small" clearable/>
                <span>图号/型号：</span>
                <el-input v-model="materialSpec1" placeholder="图号/型号" style="width: 170px" size="small" clearable/>
                <el-button type="success" size="small" icon="el-icon-search" style="margin-left:10px" @click="pageCurrent1=1;pageSize1=10;total1=0;searchMaterial1()">查询</el-button>
              </div>
              <el-table ref="multipleTable" :data="tableData10" :header-cell-style="{background: '#2283D4',color: 'white'}" size="mini" style="width: 97%;margin-top:10px" height="300px" border highlight-current-row @selection-change="handleSelectionChange">
                <el-table-column type="selection" align="center" width="50px"/>
                <el-table-column align="center" label="名称">
                  <template slot-scope="scope">
                    {{ scope.row.名称 }}
                  </template>
                </el-table-column>
                <el-table-column align="center" label="图号/型号">
                  <template slot-scope="scope">
                    {{ scope.row.代号 }}
                  </template>
                </el-table-column>
                <el-table-column align="center" label="单位">
                  <template slot-scope="scope">
                    {{ scope.row.单位 }}
                  </template>
                </el-table-column>
              </el-table>
              <div class="block" style="margin: 10px 0;">
                <el-button type="distribution" size="small" icon="el-icon-bottom" @click="selectInput()">选入</el-button>
                <el-pagination
                  :current-page="pageCurrent1"
                  :page-sizes="[10, 20, 30, 40]"
                  :page-size="pageSize1"
                  :total="total1"
                  :pager-count="5"
                  style="display:inline-block;width:50%"
                  layout="total, sizes, prev, pager, next, jumper"
                  @size-change="handleSizeChange1"
                  @current-change="handleCurrentChange1"/>
              </div>
              <div style="margin-top: 10px">
                <el-table
                  v-loading="loading"
                  ref="table1"
                  :data="tableData4"
                  :header-cell-style="{background: '#383E4B',color: 'white'}"
                  :summary-method="getSummaries1"
                  highlight-current-row
                  show-summary
                  border
                  stripe
                  size="mini"
                  style="width: 931px"
                  height="370px">
                  <el-table-column :width="setColumnWidth('序号')" type="index" label="序号" align="center" prop=""/>
                  <el-table-column :width="setColumnWidth('采购件')" label="采购件" align="center">
                    <template slot-scope="scope">
                      {{ scope.row.采购件 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('图号或型号')" label="图号/型号" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{ scope.row.图号或型号 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="80px" label="单位" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{ scope.row.单位 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="90px" label="数量" align="center" prop="数量" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.数量" size="mini" type="number" style="margin: 0;width: 100%" @change="updateProcess1(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column width="130px" label="单价（元）" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.单价" size="mini" type="number" style="margin: 0;width: 100%" @change="updateProcess1(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column width="110px" label="金额（元）" align="center" prop="金额">
                    <template slot-scope="scope">
                      {{ (scope.row.数量 * scope.row.单价).toFixed(2) }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('备注')" label="采购备注" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.采购备注" size="mini" style="margin: 0;width: 100%" @change="updateProcess1(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                      <!--<el-button v-if="scope.row.edit" type="text" size="mini" @click="confirmEdit(scope.row)">确定</el-button>-->
                      <!--<el-button v-if="scope.row.edit" type="text" size="mini" @click="cancel(scope.row)">取消</el-button>-->
                      <el-button type="text" size="mini" icon="el-icon-minus" @click="handleDeleteItem(scope.row)"/>
                    </template>
                  </el-table-column>
                </el-table>
                <!--<el-button icon="el-icon-circle-plus-outline" size="mini" @click="createProduct"/>-->
              </div>
              <!--            </el-card>-->
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible" title="采购合同" center width="320px">
        <el-form ref="form" :model="form" :rules="rules" label-position="center" label-width="80px" class="demo-ruleForm">
          <el-form-item label="供应商" prop="供应商">
            <el-select v-model="form.供应商" style="width:150px;" placeholder="供应商" size="small" filterable clearable>
              <el-option
                v-for="item in supplier"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="callOff('form')">取消</el-button>
          <el-button type="distribution" size="small" @click="createContract('form')">确定</el-button>
        </div>
      </el-dialog>

      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible1" title="耗材采购" center width="320px">
        <el-form ref="form1" :model="form1" :rules="rules1" label-position="center" label-width="80px" class="demo-ruleForm">
          <el-form-item label="供应商" prop="供应商">
            <el-select v-model="form1.供应商" style="width:150px;" placeholder="供应商" size="small" filterable clearable>
              <el-option
                v-for="item in supplier"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="callOff1('form1')">取消</el-button>
          <el-button type="distribution" size="small" @click="createContract1('form1')">确定</el-button>
        </div>
      </el-dialog>

      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible3" title="更替物料" center style="min-height: 300px;" width="630px">
        <el-row style="margin-bottom: 10px">
          <span>名称：</span>
          <el-input v-model="materialName" placeholder="名称" style="width: 170px" size="small" clearable/>
          <span>图号/型号：</span>
          <el-input v-model="materialSpec" placeholder="图号/型号" style="width: 170px" size="small" clearable/>
          <el-button type="success" size="small" icon="el-icon-search" style="margin-left:10px" @click="pageCurrent2=1;pageSize2=10;total2=0;searchMaterial()">查询</el-button>
        </el-row>
        <el-table :data="tableData5" :header-cell-style="{background: '#383E4B',color: 'white'}" size="mini" style="width: 97%;max-height: 300px;margin-top:15px" height="400px" border highlight-current-row @row-click="selectNewMaterial">
          <el-table-column align="center" label="名称">
            <template slot-scope="scope">
              {{ scope.row.名称 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="图号/型号">
            <template slot-scope="scope">
              {{ scope.row.代号 }}
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin: 10px 0;">
          <el-pagination
            :current-page="pageCurrent2"
            :page-sizes="[10, 20, 30, 40, 100]"
            :page-size="pageSize2"
            :total="total2"
            :pager-count="5"
            style="display:inline-block;width:50%"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"/>
        </div>
        <div>
          <span style="font-size: large;color: red">将原物料替换为: {{ materialNew }}</span>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="dialogFormVisible3=false">取消</el-button>
          <el-button type="primary" size="small" @click="submitMaterialChange">确定</el-button>
        </div>
      </el-dialog>
      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible4" title="图片" center style="" width="600px">
        <el-image v-for="url in urls" :key="url" :src="url" :preview-src-list="urls" lazy style="width: 500px; height: 500px"/>
      </el-dialog>
      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible2" title="上传图片" center style="height: 800px" width="30%">
        <el-upload
          id="invoiceScan"
          ref="upload"
          :multiple="true"
          :auto-upload="false"
          :on-success="uploadSuccess"
          :before-upload="beforeUpload"
          :on-exceed="warningExceed"
          :limit="limit"
          :data="Data"
          :action="upload"
          style="margin-left: 60px"
          list-type="picture-card">
          <i class="el-icon-plus"/>
        </el-upload>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible2=false">取消</el-button>
          <el-button type="primary" style="width: 70px" @click="submitPicture()">确定</el-button>
        </div>
      </el-dialog>
      <el-dialog v-el-drag-dialog :visible.sync="dialogVisible" width="350px">
        <div v-for="(file, key) in hadFile" :key="key">
          <div class="wrapper">
            <div class="content">
              <div v-if="file.suffix==='pdf'" class="icon"><svg-icon icon-class="pdf" /></div>
              <div v-else-if="file.suffix==='docx'||file.suffix === 'doc'" class="icon"><svg-icon icon-class="doc" /></div>
              <div v-else-if="file.suffix==='xlsx' || file.suffix === 'xls'" class="icon"><svg-icon icon-class="excel" /></div>
              <div v-else-if="file.suffix==='pptx' || file.suffix === 'ppt'" class="icon"><svg-icon icon-class="ppt" /></div>
              <div v-else-if="file.suffix==='jpg' || file.suffix === 'jpeg'|| file.suffix === 'png'" class="icon"><svg-icon icon-class="pic" /></div>
              <div v-else class="icon"><svg-icon icon-class="file" /></div>
              <a id="appUrl" :href="file.url" target="view_window"><div class="info">{{ file.name }}</div></a>
            </div>
          </div>
        </div>
      </el-dialog>
      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisibleReturnContract" center width="1120px">
        <div style="width: 100%;overflow: hidden">
          <el-table
            :data="tableData100"
            :header-cell-style="{background: '#2283D4',color: 'white'}"
            highlight-current-row
            border
            stripe
            size="mini"
            style="width: 1090px;margin-top: 10px;"
            height="440px">
            <el-table-column width="80px" label="类型" align="center">
              <template slot-scope="scope">
                {{ scope.row.类型 }}
              </template>
            </el-table-column>
            <el-table-column width="150px" label="物料名称" show-overflow-tooltip align="center">
              <template slot-scope="scope">
                {{ scope.row.物料名称 }}
              </template>
            </el-table-column>
            <el-table-column width="150px" label="供应商" show-overflow-tooltip align="center">
              <template slot-scope="scope">
                {{ scope.row.供应商 }}
              </template>
            </el-table-column>
            <el-table-column width="180px" label="采购合同" show-overflow-tooltip align="center">
              <template slot-scope="scope">
                {{ scope.row.采购合同 }}
              </template>
            </el-table-column>
            <el-table-column :width="setColumnWidth('数量')" label="退货数量" align="center">
              <template slot-scope="scope">
                {{ scope.row.退货数量 }}
              </template>
            </el-table-column>
            <el-table-column width="200px" label="退货原因" align="center" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.退货原因 }}
              </template>
            </el-table-column>
            <el-table-column :width="setColumnWidth('姓名')" label="操作人" align="center">
              <template slot-scope="scope">
                {{ scope.row.退货人 }}
              </template>
            </el-table-column>
            <el-table-column label="退货时间" align="center">
              <template slot-scope="scope">
                {{ scope.row.退货时间 }}
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { url } from '@/utils/request'
import { MESDownloadFile } from '@/utils/request'
import request from '@/utils/request'
export default {
  data() {
    return {
      numberReturnedItems: '',
      dialogFormVisibleReturnContract: false,
      tableData100: [],
      hadFile: [],
      dialogVisible: false,
      purchaseContractID: '', // 采购合同流水号
      checked: false,
      checkedsValue: '',
      PartType: '物料采购',
      supplier: [], // 供应商数组
      dateRange: '', // 提交日期
      urls: [],
      purchaseNumber: '',
      contractValue: '',
      contractNumber: '',
      orderNumberValue: '',
      orderNumber: [],
      productNameValue: '',
      productName: [],
      purchasedPartsValue: '',
      purchasedParts: [],
      productpartNameValue: '',
      productpartName: [],
      partNameValue: '',
      partName: [],
      materialName: '',
      materialSpec: '',
      materialName1: '',
      tableData10: [],
      multipleSelection: [],
      multipleSelection_variable: [],
      materialSpec1: '',
      materialNum: '',
      materialNumber: '',
      materialNew: '',
      materialNewValue: '',
      materialValue: '',
      partsValue: '',
      form: {
        供应商: ''
      },
      rules: {
        供应商: [{ required: true, message: '请选择供应商', trigger: 'change' }]
      },
      form1: {
        供应商: ''
      },
      rules1: {
        供应商: [{ required: true, message: '请选择供应商', trigger: 'change' }]
      },
      loading: false, // 数据加载
      total: 0, // 分页总数
      total1: 0, // 分页总数
      total2: 0, // 分页总数
      tableData: [], //
      tableData1: [], //
      tableData2: [], //
      tableData3: [], //
      tableData4: [], //
      tableData5: [], //
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible3: false,
      dialogFormVisible4: false,
      dialogFormVisible2: false, // 增加图片
      limit: 5,
      Data: {},
      upload: url,
      pageCurrent: 1, // 分页当前页
      pageSize: 100, // 分页每页显示条数
      pageCurrent1: 1, // 分页当前页
      pageSize1: 100, // 分页每页显示条数
      pageCurrent2: 1, // 分页当前页
      pageSize2: 10, // 分页每页显示条数
      orderName: '', // 排序列名
      order: '', // 排序方式,
      numberPart: '' // 标准件和外购件流水号
    }
  },
  computed: {
    ...mapGetters([
      'id',
      'token'
    ])
  },
  updated() {
    this.$nextTick(() => {
      this.$refs['table'].doLayout()
      this.$refs['table1'].doLayout()
    })
  },
  created() {
    this.fetchData()
    this.searchTable()
    this.searchContract()
    this.searchNumber()
  },
  methods: {
    viewReturnedContracts() {
      this.dialogFormVisibleReturnContract = true
      this.searchTable1()
      this.updateNumber()
    },
    searchTable1() {
      var param = []
      var Data = this.CreateData('11', '仓储管理_入库记录退货_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData100 = response.data
      })
    },
    updateNumber() {
      var param = []
      var Data = this.CreateData('12', '仓储管理_入库记录退货_查看', param)
      this.ExecDatabase(Data).then(response => {
        this.searchNumber()
      })
    },
    searchNumber() {
      var param = []
      var Data = this.CreateData('11', '仓储管理_入库记录退货_未查看数量', param)
      this.ExecDatabase(Data).then(response => {
        this.numberReturnedItems = response.data[0].数量
      })
    },
    // 查看零件图
    getNum(row) {
      this.dialogVisible = true
      this.getFileList(row.图号或型号)
    },
    async getFileList(value) {
      this.hadFile = []
      if (value) {
        await request({
          url: '',
          method: 'post',
          data: {
            type: '3',
            name: `select * from 机加工MES_零件图PDF表 where 是否启用 = 1 and name = '${value}'`
          }
        }).then(data => {
          this.suffix = data.data
          if (data.data.length > 0) {
            const server = `${MESDownloadFile}`.split('/')
            data.data.map(item => {
              this.hadFile.push({
                url: `http://${server[2]}/webpage/part/${item.uid}.${item.suffix}`,
                name: `${item.name}.${item.suffix}`,
                suffix: item.suffix,
                id: item.uid
              })
            })
          }
        })
      }
    },
    useInventory(row) {
      this.$confirm('是否使用库存?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['标准件和外购件流水号', row.标准件和外购件流水号]
        var Data = this.CreateData('12', '采购管理_采购合同选入项_使用库存', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('使用库存成功')
            this.searchTable()
          } else {
            this.$message.error('使用库存失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消提交'
        })
      })
    },
    fetchData() {
      this.getOrderNumberType()
      this.getSupplier()
    },
    getMaterial(row) {
      this.materialValue = row.物料流水号
      this.partsValue = row.标准件和外购件流水号
    },
    getOrderNumberType() {
      var param = []
      var Data = this.CreateData('11', '采购管理_订单信息_列表_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.orderNumber.push({
            label: response.data[i].订单编号,
            value: response.data[i].订单流水号
          })
        }
      })
    },
    getSupplier() {
      var param = []
      var Data = this.CreateData('11', '供应商_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.supplier.push({
            label: response.data[i].供应商名称,
            value: response.data[i].供应商流水号
          })
        }
      })
    },
    getproductpartName() {
      this.productNameValue = ''
      this.productName = []
      if (this.orderNumberValue) {
        var param = []
        param[0] = ['订单流水号', this.orderNumberValue]
        var Data = this.CreateData('11', '订单信息_产品信息_查询数据', param)
        this.ExecDatabase(Data).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.productName.push({
              label: response.data[i].产品名称,
              value: response.data[i].组件流水号
            })
          }
        })
      }
    },
    Disappear(row) {
      var param = []
      param[0] = ['标准件和外购件流水号', row.标准件和外购件流水号]
      var Data = this.CreateData('12', '采购管理_采购合同选入项_隐藏', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('隐藏成功')
          this.searchTable()
          this.dialogFormVisible = false
        } else {
          this.$message.error('隐藏失败')
        }
      })
    },
    Recovery(row) {
      var param = []
      param[0] = ['标准件和外购件流水号', row.标准件和外购件流水号]
      var Data = this.CreateData('12', '采购管理_采购合同选入项_恢复', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('恢复成功')
          this.searchTable()
          this.dialogFormVisible = false
        } else {
          this.$message.error('恢复失败')
        }
      })
    },
    createContract(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['供应商流水号', this.form.供应商]
          param[1] = ['操作者', this.id]
          var Data = this.CreateData('12', '采购管理_采购合同_增加', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('添加成功')
              this.searchContract()
              this.dialogFormVisible = false
            } else {
              this.$message.error('添加失败')
            }
          })
        }
      })
    },
    callOff(formName) {
      this.form = {}
      this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    changeState(row) {
      for (let i = 0; i < this.tableData4.length; i++) {
        if (row.采购合同明细流水号 === this.tableData4[i].采购合同明细流水号) {
          row.edit = !row.edit
        } else {
          this.tableData4[i].edit = false
        }
      }
    },
    selectIn(row) {
      if (this.purchaseNumber) {
        var param = []
        param[0] = ['标准件和外购件流水号', row.标准件和外购件流水号]
        param[1] = ['采购合同流水号', this.purchaseNumber]
        param[2] = ['数量', row.数量]
        param[3] = ['单位', row.单位]
        param[4] = ['采购备注', row.物料备注]
        var Data = this.CreateData('12', '采购管理_采购合同明细_增加', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.searchTable()
            var param1 = []
            param1[0] = ['采购合同流水号', this.purchaseNumber]
            var Data1 = this.CreateData('11', '采购管理_采购合同明细_查询数据', param1)
            this.ExecDatabase(Data1).then(response => {
              this.tableData2 = response.data
            })
            this.$message.success('选入成功')
          } else {
            this.$message.error('选入失败')
          }
        })
      } else {
        this.$message.warning('请先选择采购合同')
      }
    },
    selectOut(row) {
      var param = []
      param[0] = ['采购合同明细流水号', row.采购合同明细流水号]
      param[1] = ['标准件和外购件流水号', row.标准件和外购件流水号]
      var Data = this.CreateData('12', '采购管理_采购合同明细_删除', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.searchTable()
          var param1 = []
          param1[0] = ['采购合同流水号', this.purchaseNumber]
          var Data1 = this.CreateData('11', '采购管理_采购合同明细_查询数据', param1)
          this.ExecDatabase(Data1).then(response => {
            this.tableData2 = response.data
          })
          this.$message.success('移出成功')
        } else {
          this.$message.error('移出失败')
        }
      })
    },
    // 单价
    updateProcess(row) {
      var param = []
      param[0] = ['采购合同明细流水号', row.采购合同明细流水号]
      param[1] = ['单价', row.单价]
      param[2] = ['采购备注', row.采购备注]
      param[3] = ['数量', row.数量]
      // 参数数量与名称要与存储过程对应
      var Data = this.CreateData('12', '采购管理_采购合同明细_编辑单价', param)
      this.ExecDatabase(Data)
    },
    Submit(row) {
      if (this.tableData2.length === 0) {
        this.$message.warning('请确认查看有无采购明细')
      } else {
        if (row.采购合同流水号 !== this.purchaseNumber) {
          this.$message.warning('当前提交合同与查看的合同不一致')
        } else {
          this.$confirm('是否提交?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            var param = []
            param[0] = ['采购合同流水号', row.采购合同流水号]
            var Data = this.CreateData('12', '采购管理_采购合同_提交', param)
            this.ExecDatabase(Data).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('提交成功')
                this.searchContract()
                this.tableData2 = []
              } else {
                this.$message.error('提交失败')
              }
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消提交'
            })
          })
        }
      }
    },
    Submit1(row) {
      if (this.contractNumber !== row.采购合同流水号) {
        this.$message.warning('确认提交的合同与物料信息对应！')
        return
      }
      for (let i = 0; i < this.tableData4.length; i++) {
        if (!this.tableData4[i].数量) {
          this.$message.warning('采购物料数量不能为空！')
          return
        }
        /* if (!this.tableData4[i].单价) {
          this.$message.warning('采购物料单价不能为空！')
          return
        }*/
      }
      this.$confirm('是否提交?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['采购合同流水号', row.采购合同流水号]
        var Data = this.CreateData('12', '采购管理_耗材采购合同_提交', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('提交成功')
            this.searchTable5()
            this.tableData4 = []
          } else {
            this.$message.error('提交失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消提交'
        })
      })
    },
    warningExceed() {
      this.$message.error('仅可上传五张照片')
    },
    beforeUpload(file) { // 上传前检测
      const isJPG = /^image\/.*/.test(file.type)
      if (!isJPG) {
        this.$message.error('只能上传图片。。')
      }
      return isJPG
    },
    uploadSuccess(res) { // 上传成功回调
      this.dialogFormVisible2 = false
      this.$refs.upload.clearFiles()
    },
    updatePicture(row) {
      this.dialogFormVisible2 = true
      this.purchaseContractID = row.采购合同流水号
    },
    submitPicture() {
      var param = []
      param[0] = ['采购合同流水号', this.purchaseContractID]
      param[1] = ['文件名称', '']
      param[2] = ['文件后缀', '']
      param[3] = ['文件内容', null]
      var Data1 = this.CreateData('15', '采购合同查询_上传图片', param)
      this.Data.param = Data1
      this.$refs.upload.submit()
      this.dialogFormVisible2 = false
    },
    getData() {
      if (this.PartType === '物料采购') {
        this.searchTable()
      } else if (this.PartType === '耗材采购') {
        this.searchTable5()
      }
    },
    searchTable() {
      let orderNumberTypeValue_check, purchasedPartsValue_check, partNameValue_check, checked_check
      this.orderNumberValue ? orderNumberTypeValue_check = 1 : orderNumberTypeValue_check = 0
      this.purchasedPartsValue ? purchasedPartsValue_check = 1 : purchasedPartsValue_check = 0
      this.productNameValue ? partNameValue_check = 1 : partNameValue_check = 0
      this.checked ? checked_check = 1 : checked_check = 0
      if (this.checked === false) {
        this.checkedsValue = '1'
        checked_check = '1'
      } else {
        this.checkedsValue = '0'
      }
      var param = []
      param[0] = ['订单流水号', this.orderNumberValue]
      param[1] = ['订单流水号_check', orderNumberTypeValue_check]
      param[2] = ['组件流水号', this.productNameValue]
      param[3] = ['组件流水号_check', partNameValue_check]
      param[4] = ['采购件_check', purchasedPartsValue_check]
      param[5] = ['采购件', this.purchasedPartsValue]
      param[6] = ['排序名称', this.orderName]
      param[7] = ['排序方式', this.order]
      param[8] = ['隐藏_check', checked_check]
      param[9] = ['隐藏', this.checkedsValue]
      // 参数数量与名称要与存储过程对应
      var Data = this.CreateData('11', '采购管理_物料采购_查询数据', param, this.pageSize, this.pageCurrent)
      this.ExecDatabase(Data).then(response => {
        this.tableData = response.data.rows
        this.total = response.data.total
      })
    },
    searchContract() {
      var param = []
      param[0] = ['是否耗材采购', 0]
      param[1] = ['采购合同_check', 0]
      param[2] = ['采购合同', '']
      var Data = this.CreateData('11', '采购管理_采购合同_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData1 = response.data
      })
    },
    searchTable2(row) {
      this.tableData2 = []
      this.purchaseNumber = row.采购合同流水号
      var param = []
      param[0] = ['采购合同流水号', row.采购合同流水号]
      var Data = this.CreateData('11', '采购管理_采购合同明细_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.tableData2.push({
            标准件和外购件流水号: response.data[i].标准件和外购件流水号,
            采购合同明细流水号: response.data[i].采购合同明细流水号,
            物料流水号: response.data[i].物料流水号,
            数量: response.data[i].数量,
            采购备注: response.data[i].采购备注,
            采购件: response.data[i].采购件,
            图号或型号: response.data[i].图号或型号,
            单价: response.data[i].单价,
            采购合同流水号: response.data[i].采购合同流水号,
            材料: response.data[i].材料
          })
          this.numberPart = response.data[i].标准件和外购件流水号
        }
        // this.tableData2 = response.data
      })
    },
    searchTable5() {
      this.contractNumber = ''
      let contractValue_check
      this.contractValue ? contractValue_check = 1 : contractValue_check = 0
      var param = []
      param[0] = ['是否耗材采购', 1]
      param[1] = ['采购合同_check', contractValue_check]
      param[2] = ['采购合同', this.contractValue]
      var Data = this.CreateData('11', '采购管理_采购合同_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData3 = response.data
        if (response.data.length !== 0) {
          this.contractNumber = response.data[0].采购合同流水号
        }
      })
    },
    consumablesProcurement() {
      this.dialogFormVisible1 = true
    },
    createContract1(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['供应商流水号', this.form1.供应商]
          param[1] = ['操作者', this.id]
          var Data = this.CreateData('12', '采购管理_耗材采购合同_增加', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('添加成功')
              this.searchTable5()
              this.tableData4 = []
              this.dialogFormVisible1 = false
            } else {
              this.$message.error('添加失败')
            }
          })
        }
      })
    },
    searchTable6(row) {
      this.contractNumber = row.采购合同流水号
      this.tableData4 = []
      var param = []
      param[0] = ['采购合同流水号', row.采购合同流水号]
      var Data = this.CreateData('11', '采购管理_耗材采购合同明细_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          for (let i = 0; i < response.data.length; i++) {
            this.tableData4.push({
              // 表示将从数据库中查询到的数据，分别对应填充到表格中
              采购件: response.data[i].采购件,
              采购合同明细流水号: response.data[i].采购合同明细流水号,
              图号或型号: response.data[i].图号或型号,
              单位: response.data[i].单位,
              单价: response.data[i].单价,
              数量: response.data[i].数量,
              金额: response.data[i].金额,
              采购备注: response.data[i].采购备注,
              采购件_before: response.data[i].采购件,
              图号或型号_before: response.data[i].图号或型号,
              单位_before: response.data[i].单位,
              单价_before: response.data[i].单价,
              数量_before: response.data[i].数量,
              采购备注_before: response.data[i].采购备注,
              edit: false
            })
          }
        }
      })
    },
    callOff1(formName) {
      this.form1 = {}
      this.dialogFormVisible1 = false
      this.$refs[formName].resetFields()
    },
    cancel(row) {
      row.采购件 = row.采购件_before
      row.图号或型号 = row.图号或型号_before
      row.单位 = row.单位_before
      row.数量 = row.数量_before
      row.单价 = row.单价_before
      row.采购备注 = row.采购备注_before
      row.edit = false
    },
    // 单价
    updateProcess1(row) {
      var param = []
      param[0] = ['采购合同明细流水号', row.采购合同明细流水号]
      param[1] = ['单价', row.单价]
      param[2] = ['采购备注', row.采购备注]
      param[3] = ['数量', row.数量]
      // 参数数量与名称要与存储过程对应
      var Data = this.CreateData('12', '采购管理_耗材采购合同明细_编辑数据', param)
      this.ExecDatabase(Data)
    },
    // 确定编辑
    confirmEdit(row) {
      var param = []
      param[0] = ['数量', row.数量]
      param[1] = ['单价', row.单价]
      param[2] = ['采购备注', row.采购备注]
      param[3] = ['采购合同明细流水号', row.采购合同明细流水号]
      if (row.数量) {
        var Data = this.CreateData('12', '采购管理_耗材采购合同明细_编辑数据', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message({
              message: '信息编辑成功',
              type: 'success'
            })
            this.tableData4 = []
            var param = []
            param[0] = ['采购合同流水号', this.contractNumber]
            var Data = this.CreateData('11', '采购管理_耗材采购合同明细_查询数据', param)
            this.ExecDatabase(Data).then(response => {
              if (response.data.length !== 0) {
                for (let i = 0; i < response.data.length; i++) {
                  this.tableData4.push({
                    // 表示将从数据库中查询到的数据，分别对应填充到表格中
                    采购件: response.data[i].采购件,
                    采购合同明细流水号: response.data[i].采购合同明细流水号,
                    图号或型号: response.data[i].图号或型号,
                    单位: response.data[i].单位,
                    单价: response.data[i].单价,
                    数量: response.data[i].数量,
                    金额: response.data[i].金额,
                    采购备注: response.data[i].采购备注,
                    采购件_before: response.data[i].采购件,
                    图号或型号_before: response.data[i].图号或型号,
                    单位_before: response.data[i].单位,
                    单价_before: response.data[i].单价,
                    数量_before: response.data[i].数量,
                    采购备注_before: response.data[i].采购备注,
                    edit: false
                  })
                }
              }
            })
          } else {
            this.$message.error('信息编辑失败')
          }
        })
      } else {
        this.$message.warning('请将采购件、单价、数量信息补全')
      }
    },
    createProduct() {
      if (this.contractNumber) {
        var param = []
        param[0] = ['采购合同流水号', this.contractNumber]
        var Data = this.CreateData('12', '采购管理_耗材采购合同明细_增加数据', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.tableData4 = []
            var param = []
            param[0] = ['采购合同流水号', this.contractNumber]
            var Data = this.CreateData('11', '采购管理_耗材采购合同明细_查询数据', param)
            this.ExecDatabase(Data).then(response => {
              if (response.data.length !== 0) {
                for (let i = 0; i < response.data.length; i++) {
                  this.tableData4.push({
                    // 表示将从数据库中查询到的数据，分别对应填充到表格中
                    采购件: response.data[i].采购件,
                    采购合同明细流水号: response.data[i].采购合同明细流水号,
                    图号或型号: response.data[i].图号或型号,
                    单位: response.data[i].单位,
                    单价: response.data[i].单价,
                    数量: response.data[i].数量,
                    金额: response.data[i].金额,
                    采购备注: response.data[i].采购备注,
                    采购件_before: response.data[i].采购件,
                    图号或型号_before: response.data[i].图号或型号,
                    单位_before: response.data[i].单位,
                    单价_before: response.data[i].单价,
                    数量_before: response.data[i].数量,
                    采购备注_before: response.data[i].采购备注,
                    edit: false
                  })
                }
              }
            })
          } else {
            this.$message.error('增加失败')
          }
        })
      } else {
        this.$message.warning('请先选择合同')
      }
    },
    handleDeleteItem(row) {
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['采购合同明细流水号', row.采购合同明细流水号]
        var Data = this.CreateData('12', '采购管理_耗材采购合同明细_删除数据', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.tableData4 = []
            var param = []
            param[0] = ['采购合同流水号', this.contractNumber]
            var Data = this.CreateData('11', '采购管理_耗材采购合同明细_查询数据', param)
            this.ExecDatabase(Data).then(response => {
              if (response.data.length !== 0) {
                for (let i = 0; i < response.data.length; i++) {
                  this.tableData4.push({
                    // 表示将从数据库中查询到的数据，分别对应填充到表格中
                    采购件: response.data[i].采购件,
                    采购合同明细流水号: response.data[i].采购合同明细流水号,
                    图号或型号: response.data[i].图号或型号,
                    单位: response.data[i].单位,
                    单价: response.data[i].单价,
                    数量: response.data[i].数量,
                    金额: response.data[i].金额,
                    采购备注: response.data[i].采购备注,
                    采购件_before: response.data[i].采购件,
                    图号或型号_before: response.data[i].图号或型号,
                    单位_before: response.data[i].单位,
                    单价_before: response.data[i].单价,
                    数量_before: response.data[i].数量,
                    采购备注_before: response.data[i].采购备注,
                    edit: false
                  })
                }
              }
            })
          } else {
            this.$message.error('删除失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    purchaseContract() {
      this.form = {}
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.dialogFormVisible = true
    },
    changeMaterial() {
      if (this.materialValue) {
        this.dialogFormVisible3 = true
      } else {
        this.$message.warning('请先选择要替换的物料')
      }
    },
    searchMaterial() {
      let materialName_check, materialSpec_check
      this.materialName ? materialName_check = 1 : materialName_check = 0
      this.materialSpec ? materialSpec_check = 1 : materialSpec_check = 0
      var param = []
      param[0] = ['名称_check', materialName_check]
      param[1] = ['名称', this.materialName]
      param[2] = ['代号_check', materialSpec_check]
      param[3] = ['代号', this.materialSpec]
      var Data = this.CreateData('11', '物料信息_查询', param, this.pageSize2, this.pageCurrent2)
      this.ExecDatabase(Data).then(response => {
        this.tableData5 = response.data.rows
        this.total2 = response.data.total
      })
    },
    selectNewMaterial(row) {
      this.materialNew = ''
      this.materialNewValue = row.物料流水号
      this.materialNew += row.名称 + ' ' + row.代号
    },
    submitMaterialChange() {
      var param = []
      param[0] = ['标准件和外购件流水号', this.partsValue]
      param[1] = ['原物料流水号', this.materialValue]
      param[2] = ['新物料流水号', this.materialNewValue]
      param[3] = ['申请人', this.id]
      var Data = this.CreateData('12', '采购管理_采购物料修改_修改数据', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('操作成功')
          this.dialogFormVisible3 = false
          this.searchTable()
        } else {
          this.$message.error('操作失败')
        }
      })
    },
    searchMaterial1() {
      let materialName_check, materialSpec_check
      this.materialName1 ? materialName_check = 1 : materialName_check = 0
      this.materialSpec1 ? materialSpec_check = 1 : materialSpec_check = 0
      var param = []
      param[0] = ['名称_check', materialName_check]
      param[1] = ['名称', this.materialName1]
      param[2] = ['代号_check', materialSpec_check]
      param[3] = ['代号', this.materialSpec1]
      var Data = this.CreateData('11', '物料信息_查询', param, this.pageSize1, this.pageCurrent1)
      this.ExecDatabase(Data).then(response => {
        this.tableData10 = response.data.rows
        this.total1 = response.data.total
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    selectInput() {
      if (this.multipleSelection.length === 0) {
        this.$message.warning('请选择要购买的物料！')
        return
      }
      if (!this.contractNumber) {
        this.$message.warning('请先选择合同！')
        return
      }
      const materialGroup = []
      this.multipleSelection_variable = this.multipleSelection
      this.multipleSelection = []
      for (let i = 0; i < this.multipleSelection_variable.length; i++) {
        materialGroup[i] = this.multipleSelection_variable[i].物料流水号
      }
      var param = []
      param[0] = ['物料流水号组', materialGroup]
      param[1] = ['采购合同流水号', this.contractNumber]
      var Data = this.CreateData('12', '采购管理_耗材采购合同明细_增加数据', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('选入成功')
          this.$refs.multipleTable.clearSelection()
          this.tableData4 = []
          var param = []
          param[0] = ['采购合同流水号', this.contractNumber]
          var Data = this.CreateData('11', '采购管理_耗材采购合同明细_查询数据', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data.length !== 0) {
              for (let i = 0; i < response.data.length; i++) {
                this.tableData4.push({
                  // 表示将从数据库中查询到的数据，分别对应填充到表格中
                  采购件: response.data[i].采购件,
                  采购合同明细流水号: response.data[i].采购合同明细流水号,
                  图号或型号: response.data[i].图号或型号,
                  单位: response.data[i].单位,
                  单价: response.data[i].单价,
                  数量: response.data[i].数量,
                  金额: response.data[i].金额,
                  采购备注: response.data[i].采购备注,
                  采购件_before: response.data[i].采购件,
                  图号或型号_before: response.data[i].图号或型号,
                  单位_before: response.data[i].单位,
                  单价_before: response.data[i].单价,
                  数量_before: response.data[i].数量,
                  采购备注_before: response.data[i].采购备注,
                  edit: false
                })
              }
            }
          })
        } else {
          this.$message.success('选入失败')
        }
      })
    },
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        } else if (index === 4) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index]
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 7) {
          const values = data.map(item => Number(item['数量']) * Number(item['单价']))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(2)
          } else {
            sums[index] = 'N/A'
          }
        }
      })
      return sums
    },
    getSummaries1(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        } else if (index === 4) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index]
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 6) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(2)
          } else {
            sums[index] = 'N/A'
          }
        }
      })
      return sums
    },
    printDrawings(row) {
      this.dialogFormVisible4 = true
      this.urls = []
      var param = []
      param[0] = ['标准件和外购件流水号', row.标准件和外购件流水号]
      var Data = this.CreateData('11', '采购合同_图片_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          if (response.data[i].文件内容 !== null) {
            this.urls.push('data:image/png;base64,' + response.data[i].文件内容)
          }
        }
      })
    },
    contract(row) {},
    sortChange(column) {
      if (column.prop === '采购件') {
        this.orderName = 1
      } else if (column.prop === '订单编号') {
        this.orderName = 2
      } else if (column.prop === '产品名称') {
        this.orderName = 3
      } else {
        this.orderName = 0
      }
      if (column.order === 'ascending') {
        this.order = 1
      } else if (column.order === 'descending') { this.order = 2 } else {
        this.order = ''
      }
      this.searchTable()
    },
    handleSizeChange2(val) {
      this.pageCurrent2 = 1
      this.pageSize2 = val
      this.searchMaterial()
    },
    handleCurrentChange2(val) {
      this.pageCurrent2 = val
      this.searchMaterial()
    },
    handleSizeChange1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      this.searchMaterial1()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.searchMaterial1()
    }
  }
}
</script>
<style scoped lang="scss">
  ::v-deep .el-card__body{
    padding: 0px!important;
  }
</style>
<style scoped>
  .el-form--label-left >>> .el-form-item__label {
    text-align: right;
  }
  >>>.el-dialog--center .el-dialog__body {
    text-align: initial;
    padding: 20px 30px 20px
  }
  >>>.el-dialog__header {
    padding: 20px 20px 0px;
  }
  >>>.el-dialog__footer {
    padding: 0px 20px 20px;
    /*text-align: right;*/
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }
  >>>.el-form-item {
    margin-bottom: 13px;
  }
  .wrapper{
    width: 90%;
    height: 50px;
    overflow: hidden;
    border: 1px solid #b8c7d9;
    /*float: left;*/
    margin: 10px;
  }
  .content{
    position: relative;
    padding: 8px 8px 0 8px;
  }
  .action{
    position: absolute;
    top: 2px;
    right: 8px;
  }
  .delete{
    padding: 0 5px;
    border-radius: 3px;
    color: #0f84b0;
    font-size: 12px;
  }
  .delete:hover{
    background: -webkit-linear-gradient(top,#0ba9e3,#0099d3);
    color: #fff;
  }
  a{
    text-decoration: none;
  }
  .icon{
    width: 30px;
    height: 30px;
    display: inline-block;
    margin-right: 7px;
    margin-top: 2px;
    font-size: 26px;
  }
  .info{
    width: 160px;
    height: 50px;
    position: absolute;
    left: 44px;
    line-height: 30px;
    display: inline-block;
    color: #999;
  }
</style>
