<template>
  <div class="app-container">
    <el-card style="height: 850px">
      <div style="margin-top: 7px; margin-bottom: 7px">
        <el-input v-model="materialNameValue" style="width:150px" placeholder="物料名称" size="small" clearable/>
        <el-input v-model="materialToolValue" style="width:150px" placeholder="图号/型号" size="small" clearable/>
        <el-select v-model="materialTypeValue" style="width:100px;" placeholder="物料类型" size="small" filterable clearable>
          <el-option
            v-for="item in materialType"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <span style="font-size: 13px;color: black">修改时间：</span>
        <el-date-picker
          v-model="dateRange"
          size="small"
          type="daterange"
          align="center"
          style="width: 240px;"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          range-separator="～"
          start-placeholder="开始日期"
          end-placeholder="结束日期"/>
        <el-button type="primary" plain icon="el-icon-search" size="small" style="margin-left:10px" @click="pageCurrent=1;searchTable()">查询</el-button>
        <!--        <el-button type="distribution" icon="el-icon-plus" size="small" style="margin-left:10px" @click="materialPlus">物料</el-button>-->
        <!--        <el-badge :value="value" :max="99" class="item">-->
        <!--          <el-button type="warning" plain size="small" style="margin-left:10px" @click="purchaseChangeRequest">采购变更申请</el-button>-->
        <!--        </el-badge>-->
        <!--        <el-button type="success" icon="el-icon-edit" plain size="small" style="margin-left:10px" @click="maintainMaterial">材料维护</el-button>-->
        <el-checkbox v-model="checked" style="margin-left: 50px" @change="searchTable()">专机</el-checkbox>
      </div>
      <el-table v-loading="loading" :data="tableData" highlight-current-row border stripe size="small" style="width: 1380px; margin-top: 10px" height="740px" @sort-change="sortChange">
        <el-table-column align="center" label="照片" width="80">
          <template slot-scope="scope">
            <el-popover
              v-if="scope.row.文件内容 && scope.row.文件内容 !== 'null'"
              placement="top-start"
              width="400"
              trigger="hover">
              <el-button type="text" style="float:right" @click="deletePhoto(scope.row)">删除</el-button>
              <el-image :src="scope.row.文件内容 && scope.row.文件内容 !== 'null' ? ('data:image/png;base64,' + scope.row.文件内容) : ''">
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"/>
                </div>
              </el-image>
              <el-image slot="reference" :src="scope.row.文件内容 && scope.row.文件内容 !== 'null' ? ('data:image/png;base64,' + scope.row.文件内容) : ''" style="width:43px;margin-top: 7px">
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"/>
                </div>
              </el-image>
            </el-popover>
            <span v-else>—</span>
          </template>
        </el-table-column>
        <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 label="物料名称" align="center" sortable="名称" prop="名称" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.名称 }}
          </template>
        </el-table-column>
        <el-table-column width="80px" label="物料类型" align="center" prop="物料类型" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.物料类型 }}
          </template>
        </el-table-column>
        <el-table-column width="169px" label="图号/型号" align="center" sortable="代号" prop="代号" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.代号 }}
          </template>
        </el-table-column>
        <el-table-column width="80px" 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>
          <template slot-scope="scope">
            {{ scope.row.材料 }}
          </template>
        </el-table-column>
        <el-table-column :width="setColumnWidth('单位')" 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" prop="类型" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.类型名称 }}
          </template>
        </el-table-column>
        <el-table-column width="170px" 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="setColumnWidth('姓名')" label="修改人" align="center" prop="修改人" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.修改人 }}
          </template>
        </el-table-column>
        <el-table-column width="101px" label="操作" align="center">
          <template slot-scope="scope">
            <!--            <el-button type="text" icon="el-icon-edit" size="mini" style="margin-right: 10px" @click="handleEdit(scope.row)"/>-->
            <!--            <el-button type="text" icon="el-icon-delete" size="mini" style="margin-right: 10px" @click="handleDelete(scope.row)"/>-->
            <el-tooltip :open-delay="700" effect="dark" content="上传照片" placement="top">
              <el-button :disabled="scope.row.文件内容 && scope.row.文件内容 !== 'null'" type="text" icon="el-icon-upload" size="mini" @click="handlePicture(scope.row)"/>
            </el-tooltip>
            <el-tooltip :open-delay="700" effect="dark" content="查看图纸" placement="top">
              <el-button type="text" icon="el-icon-picture-outline" size="mini" @click="getNum(scope.row)"/>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="pageCurrent"
          :page-sizes="[10, 20, 30, 40, 100]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChanges"
          @current-change="handleCurrentChanges"/>
      </div>
      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible" :title="title" center width="360px">
        <el-form ref="form" :model="form" :rules="rules" label-position="center" label-width="100px" class="demo-ruleForm">
          <el-form-item label="物料名称" prop="物料名称">
            <el-input v-model="form.物料名称" style="width:150px;" placeholder="物料名称" size="small" clearable/>
          </el-form-item>
          <el-form-item label="图号/型号" prop="图号或型号">
            <el-input v-model="form.图号或型号" style="width:150px;" placeholder="图号/型号" size="small" clearable/>
          </el-form-item>
          <el-form-item label="库位" prop="库位">
            <el-select v-model="form.库位" style="width:150px;" placeholder="库位" size="small" filterable clearable>
              <el-option
                v-for="item in inventoryLocation"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="材料" prop="材料">
            <el-select v-model="form.材料" style="width:150px;" placeholder="材料" size="small" filterable clearable>
              <el-option
                v-for="item in materialScience"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="单位" prop="单位">
            <el-select v-model="form.单位" style="width:150px;" placeholder="单位" size="small" filterable clearable>
              <el-option
                v-for="item in unit"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="类型" prop="类型">
            <el-select v-model="form.类型" style="width:150px;" placeholder="类型" size="small" filterable clearable>
              <el-option
                v-for="item in materialType"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="物料库" prop="物料库">
            <el-select v-model="form.物料库" style="width:150px;" placeholder="物料库" size="small" filterable clearable>
              <el-option
                v-for="item in checkeds"
                :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 v-show="title==='新增物料'" type="distribution" size="small" @click="submitOrder('form')">确定</el-button>
          <el-button v-show="title==='编辑物料'" type="distribution" size="small" @click="submitUpdate('form')">确定</el-button>
        </div>
      </el-dialog>
      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible1" width="1283px">
        <el-table :data="tableData1" highlight-current-row border stripe size="small" style="width: 1241px; margin-top: 10px" height="540px">
          <el-table-column :width="setColumnWidth('序号')" label="序号" type="index" align="center"/>
          <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="setColumnWidth('产品名称')" label="产品名称" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.产品名称 }}
            </template>
          </el-table-column>
          <el-table-column width="165px" label="原物料名称" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.原名称 }}
            </template>
          </el-table-column>
          <el-table-column width="140px" label="原图号/型号" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.原代号 }}
            </template>
          </el-table-column>
          <el-table-column width="165px" label="新物料名称" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.新名称 }}
            </template>
          </el-table-column>
          <el-table-column width="140px" label="新图号/型号" align="center" show-overflow-tooltip>
            <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="setColumnWidth('日期')" label="申请时间" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.申请时间 }}
            </template>
          </el-table-column>
          <el-table-column width="150px" label="操作" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-circle-check"
                @click="agree(scope.row)">同意</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-circle-close"
                @click="disagree(scope.row)">不同意</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible2" width="383px">
        <el-input v-model="material" style="width:150px" placeholder="材料名称" size="small" clearable/>
        <el-button type="primary" plain icon="el-icon-search" size="small" style="margin-left:10px" @click="pageCurrent1=1;searchTable2()">查询</el-button>
        <el-button type="distribution" icon="el-icon-plus" size="small" style="margin-left:10px" @click="addMaterial">材料</el-button>
        <el-table :data="tableData2" highlight-current-row border stripe size="small" style="width: 341px; margin-top: 10px" height="402px">
          <el-table-column :width="setColumnWidth('序号')" label="序号" type="index" align="center"/>
          <el-table-column label="材料名称" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.材料 }}
            </template>
          </el-table-column>
          <el-table-column width="100px" label="操作" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="updateMaterial(scope.row)"/>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="deleteMaterial(scope.row)"/>
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <el-pagination
            :current-page="pageCurrent1"
            :page-sizes="[10, 20, 30, 40, 100]"
            :page-size="pageSize1"
            :total="total1"
            layout="total, prev, pager, next"
            @size-change="handleSizeChanges1"
            @current-change="handleCurrentChanges1"/>
        </div>
      </el-dialog>
      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible3" :title="title1" center width="360px">
        <el-form ref="form1" :model="form1" :rules="rules1" label-position="center" label-width="100px" class="demo-ruleForm">
          <el-form-item label="材料名称" prop="材料名称">
            <el-input v-model="form1.材料名称" style="width:150px;" placeholder="材料名称" size="small" clearable/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="callOff1('form')">取消</el-button>
          <el-button v-show="title1==='新增材料'" type="distribution" size="small" @click="submitAdd('form1')">确定</el-button>
          <el-button v-show="title1==='编辑材料'" type="distribution" size="small" @click="submitUpdate1('form1')">确定</el-button>
        </div>
      </el-dialog>
      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisiblePicture" title="上传图片" center style="height: 800px" width="17%">
        <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="dialogFormVisiblePicture=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-card>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { readImg, url, MESDownloadFile } from '@/utils/request'
import request from '@/utils/request'
export default {
  data() {
    return {
      limit: 5,
      Data: {},
      upload: url,
      // 以上是上传照片用到的
      dialogFormVisible2: false,
      readFile: readImg,
      dialogFormVisible1: false,
      dialogFormVisible: false,
      dialogFormVisible3: false,
      dialogFormVisiblePicture: false,
      dialogVisible: false,
      hadFile: [],
      form: {
        物料编码: '',
        物料名称: '',
        图号或型号: '',
        材料: '',
        库位: '',
        单位: '',
        类型: '',
        物料库: '',
        原图号或型号: '',
        原物料名称: ''
      },
      form1: {
        材料名称: ''
      },
      value: 0,
      rules: {
        物料名称: [{ required: true, message: '请输入物料名称', trigger: 'blur' }],
        图号或型号: [{ required: true, message: '请输入图号或型号', trigger: 'blur' }],
        单位: [{ required: true, message: '请选择单位', trigger: 'change' }],
        库位: [{ required: true, message: '请选择库位', trigger: 'change' }],
        类型: [{ required: true, message: '请选择类型', trigger: 'change' }],
        物料库: [{ required: true, message: '请选择物料库', trigger: 'change' }]
      },
      rules1: {
        材料名称: [{ required: true, message: '请输入材料名称', trigger: 'blur' }]
      },
      materialNameValue: '',
      materialToolValue: '',
      materialTypeValue: '',
      materialValue: '',
      materialScience: [],
      inventoryLocation: [], // 库位
      unit: [],
      dateRange: '',
      title: '',
      title1: '',
      material: '',
      materialNumber: '',
      materialType: [
        {
          value: 2,
          label: '自制'
        }, {
          value: 1,
          label: '外购'
        }
      ], // 类型数组
      loading: false, // 数据加载
      total: 0, // 分页总数
      total1: 0, // 分页总数
      tableData: [],
      tableData1: [],
      tableData2: [],
      pageCurrent1: 1, // 分页当前页
      pageSize1: 10, // 分页每页显示条数
      pageCurrent: 1, // 分页当前页
      pageSize: 20, // 分页每页显示条数
      orderName: '', // 排序列名
      order: '', // 排序方式
      checked: false,
      checkedsValue: '', // 物料库变量
      checkeds: [
        {
          value: 2,
          label: '专机'
        }, {
          value: 1,
          label: '通用'
        }
      ] // 物料库数组
    }
  },
  computed: {
    ...mapGetters([
      'id',
      'token'
    ])
  },
  created() {
    this.getMaterialScience()
    this.getUnit()
    this.searchTable1()
    this.getInventoryLocation()
  },
  methods: {
    // 查看零件图
    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
              })
            })
          }
        })
      }
    },
    handlePicture(row) {
      this.dialogFormVisiblePicture = true
      this.materialSerialNumber = row.物料流水号
    },
    uploadSuccess(res) { // 上传成功回调
      this.dialogFormVisiblePicture = false
      this.$refs.upload.clearFiles()
    },
    beforeUpload(file) { // 上传前检测
      const isJPG = /^image\/.*/.test(file.type)
      if (!isJPG) {
        this.$message.error('只能上传图片。。')
      }
      return isJPG
    },
    warningExceed() {
      this.$message.error('仅可上传五张照片')
    },
    submitPicture() {
      var param = []
      param[0] = ['物料流水号', this.materialSerialNumber]
      param[1] = ['文件名称', '']
      param[2] = ['文件后缀', '']
      param[3] = ['文件内容', null]
      var Data1 = this.CreateData('15', '库存管理_物料_图片_上传图片', param)
      this.Data.param = Data1
      this.$refs.upload.submit()
      this.searchTable()
      this.dialogFormVisiblePicture = false
    },
    // 删除照片
    deletePhoto(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: '取消删除'
        })
      })
    },
    getMaterialScience() {
      var param = []
      var Data = this.CreateData('11', 'PDM_零件明细表_材料_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.materialScience.push({
            label: response.data[i].材料,
            value: response.data[i].材料流水号
          })
        }
      })
    },
    getInventoryLocation() {
      var param = []
      var Data = this.CreateData('11', '库存管理_货位_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.inventoryLocation.push({
            label: response.data[i].货位名称,
            value: response.data[i].货位流水号
          })
        }
      })
    },
    getUnit() {
      var param = []
      var Data = this.CreateData('11', '单位_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.unit.push({
            label: response.data[i].单位,
            value: response.data[i].单位流水号
          })
        }
      })
    },
    materialPlus() {
      this.title = '新增物料'
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.form.物料名称 = ''
      this.form.图号或型号 = ''
      this.form.单位 = ''
      this.form.材料 = ''
      this.form.库位 = 2514
      this.form.类型 = ''
      this.form.物料库 = ''
      this.dialogFormVisible = true
    },
    submitOrder(formName) {
      if (this.form.材料 === null || this.form.材料 === '') {
        this.form.材料 = 0
      }
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['名称', this.form.物料名称]
          param[1] = ['代号', this.form.图号或型号]
          param[2] = ['类型', this.form.类型]
          var Data = this.CreateData('11', '物料标准维护_验证图号', param)
          this.ExecDatabase(Data).then(response => {
            if (Number(response.data[0].Column1) === 0) {
              var param = []
              param[0] = ['物料名称', this.form.物料名称]
              param[1] = ['图号', this.form.图号或型号]
              param[2] = ['单位流水号', this.form.单位]
              param[3] = ['材料流水号', this.form.材料]
              param[4] = ['类型', this.form.类型]
              param[5] = ['货位流水号', this.form.库位]
              param[6] = ['物料库流水号', this.form.物料库]
              param[7] = ['人员编号', this.id]
              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('添加失败')
                }
              })
            } else {
              this.$message.error('新增的物料已存在')
            }
          })
        }
      })
    },
    callOff(formName) {
      this.form.物料编号 = ''
      this.form.物料名称 = ''
      this.form.图号或型号 = ''
      this.form.材料 = ''
      this.form.单位 = ''
      this.form.类型 = ''
      this.form.物料库 = ''
      this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    purchaseChangeRequest() {
      this.dialogFormVisible1 = true
    },
    searchTable1() {
      var param = []
      var Data = this.CreateData('11', '采购管理_采购物料修改确认_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData1 = response.data
        this.value = response.data.length
      })
    },
    agree(row) {
      var param = []
      param[0] = ['物料变更记录流水号', row.物料变更记录流水号]
      param[1] = ['标准件和外购件流水号', row.标准件和外购件流水号]
      param[2] = ['确认通过状态', 1]
      param[3] = ['确认人', this.id]
      param[4] = ['原物料流水号', row.原物料流水号]
      var Data = this.CreateData('12', '采购管理_采购物料修改确认_是否通过', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('操作成功')
          this.searchTable1()
        } else {
          this.$message.error('操作失败')
        }
      })
    },
    disagree(row) {
      var param = []
      param[0] = ['物料变更记录流水号', row.物料变更记录流水号]
      param[1] = ['标准件和外购件流水号', row.标准件和外购件流水号]
      param[2] = ['确认通过状态', 2]
      param[3] = ['确认人', this.id]
      param[4] = ['原物料流水号', row.原物料流水号]
      var Data = this.CreateData('12', '采购管理_采购物料修改确认_是否通过', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('操作成功')
          this.searchTable1()
        } else {
          this.$message.error('操作失败')
        }
      })
    },
    handleEdit(row) {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.title = '编辑物料'
      this.form.物料编码 = row.物料编码
      this.form.物料名称 = row.名称
      this.form.图号或型号 = row.代号
      this.form.原物料名称 = row.名称
      this.form.原图号或型号 = row.代号
      this.form.材料 = Number(row.材料流水号) === 3 ? null : Number(row.材料流水号)
      this.form.库位 = Number(row.货位流水号)
      this.form.单位 = Number(row.单位流水号)
      this.form.类型 = Number(row.类型)
      this.form.物料库 = Number(row.物料库流水号)
      this.materialValue = row.物料流水号
      this.dialogFormVisible = true
    },
    submitUpdate(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.form.物料名称 === this.form.原物料名称 && this.form.图号或型号 === this.form.原图号或型号) {
            var param1 = []
            param1[0] = ['物料名称', this.form.物料名称]
            param1[1] = ['图号', this.form.图号或型号]
            param1[2] = ['单位流水号', this.form.单位]
            param1[3] = ['材料流水号', this.form.材料]
            param1[4] = ['类型', this.form.类型]
            param1[5] = ['物料流水号', this.materialValue]
            param1[6] = ['操作者', this.id]
            param1[7] = ['物料编码', this.form.物料编码]
            param1[8] = ['货位流水号', this.form.库位]
            param1[9] = ['物料库流水号', this.form.物料库]
            var Data1 = this.CreateData('12', '物料管理_编辑', param1)
            this.ExecDatabase(Data1).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('编辑成功')
                this.searchTable()
                this.dialogFormVisible = false
              } else {
                this.$message.error('编辑失败')
              }
            })
          } else {
            var param = []
            param[0] = ['名称', this.form.物料名称]
            param[1] = ['代号', this.form.图号或型号]
            param[2] = ['类型', this.form.类型]
            var Data = this.CreateData('11', '物料标准维护_验证图号', param)
            this.ExecDatabase(Data).then(response => {
              if (Number(response.data[0].Column1) === 0) {
                var param = []
                param[0] = ['物料名称', this.form.物料名称]
                param[1] = ['图号', this.form.图号或型号]
                param[2] = ['单位流水号', this.form.单位]
                param[3] = ['材料流水号', this.form.材料]
                param[4] = ['类型', this.form.类型]
                param[5] = ['物料流水号', this.materialValue]
                param[6] = ['操作者', this.id]
                param[7] = ['物料编码', this.form.物料编码]
                param[8] = ['货位流水号', this.form.库位]
                param[9] = ['物料库流水号', this.form.物料库]
                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('编辑失败')
                  }
                })
              } else {
                this.$message.error('更改后的物料已存在')
              }
            })
          }
        }
      })
    },
    handleDelete(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: '已取消删除'
        })
      })
    },
    // searchTableCS() {
    //   let materialToolValue_check, materialNameValue_check, materialTypeValue_check, dateRange_check
    //   this.materialToolValue ? materialToolValue_check = 1 : materialToolValue_check = 0
    //   this.materialNameValue ? materialNameValue_check = 1 : materialNameValue_check = 0
    //   this.materialTypeValue ? materialTypeValue_check = 1 : materialTypeValue_check = 0
    //   this.dateRange ? dateRange_check = 1 : (dateRange_check = 0, this.dateRange = '')
    //   var param = []
    //   param[0] = ['物料名称_check', materialNameValue_check]
    //   param[1] = ['物料名称', this.materialNameValue]
    //   param[2] = ['时间_check', dateRange_check]
    //   param[3] = ['开始时间', this.dateRange[0]]
    //   param[4] = ['结束时间', this.dateRange[1]]
    //   param[5] = ['图号_check', materialToolValue_check]
    //   param[6] = ['图号', this.materialToolValue]
    //   param[7] = ['类型_check', materialTypeValue_check]
    //   param[8] = ['类型', this.materialTypeValue]
    //   param[9] = ['排序名称', this.orderName]
    //   param[10] = ['排序方式', this.order]
    //   var Data = this.CreateData('11', '物料管理_查询数据', param)
    //   this.ExecDatabase(Data).then(response => {
    //     console.log('李显测试，初始数据查询', response.data)
    //     this.tableData = response.data
    //     this.total = response.data
    //   })
    // },
    searchTable() {
      let materialToolValue_check, materialNameValue_check, materialTypeValue_check, dateRange_check, checked_check
      this.materialToolValue ? materialToolValue_check = 1 : materialToolValue_check = 0
      this.materialNameValue ? materialNameValue_check = 1 : materialNameValue_check = 0
      this.materialTypeValue ? materialTypeValue_check = 1 : materialTypeValue_check = 0
      this.checked ? checked_check = 1 : checked_check = 0
      this.dateRange ? dateRange_check = 1 : (dateRange_check = 0, this.dateRange = '')
      if (this.checked === false) {
        this.checkedsValue = '1'
        checked_check = '1'
      } else {
        this.checkedsValue = '2'
      }
      var param = []
      param[0] = ['物料名称_check', materialNameValue_check]
      param[1] = ['物料名称', this.materialNameValue]
      param[2] = ['时间_check', dateRange_check]
      param[3] = ['开始时间', this.dateRange[0]]
      param[4] = ['结束时间', this.dateRange[1]]
      param[5] = ['图号_check', materialToolValue_check]
      param[6] = ['图号', this.materialToolValue]
      param[7] = ['类型_check', materialTypeValue_check]
      param[8] = ['类型', this.materialTypeValue]
      param[9] = ['排序名称', this.orderName]
      param[10] = ['排序方式', this.order]
      param[11] = ['PageCurrent', this.pageCurrent]
      param[12] = ['PageSize', this.pageSize]
      param[13] = ['PageCount', '1111', 'int', '1']
      param[14] = ['ItemCount', '1111', 'int', '1']
      param[15] = ['物料库', this.checkedsValue]
      param[16] = ['物料库_check', checked_check]
      var Data = this.CreateData('11', '物料管理_查询数据_分页', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData = response.data.result
        this.total = parseInt(response.data.output[0].ItemCount)
      })
    },
    sortChange(column) {
      if (column.prop === '名称') {
        this.orderName = 1
      } else if (column.prop === '代号') {
        this.orderName = 2
      } else {
        this.orderName = 0
      }
      if (column.order === 'ascending') {
        this.order = 1
      } else if (column.order === 'descending') { this.order = 2 } else {
        this.order = ''
      }
      this.searchTable()
    },
    maintainMaterial() {
      this.material = ''
      this.searchTable2()
      this.dialogFormVisible2 = true
    },
    searchTable2() {
      let material_check
      this.material ? material_check = 1 : material_check = 0
      var param = []
      param[0] = ['材料_check', material_check]
      param[1] = ['材料', this.material]
      var Data = this.CreateData('11', 'PDM_零件明细表_材料_查询数据_条件查询', param, this.pageSize1, this.pageCurrent1)
      this.ExecDatabase(Data).then(response => {
        this.tableData2 = response.data.rows
        this.total1 = response.data.total
      })
    },
    addMaterial() {
      this.title1 = '新增材料'
      if (this.$refs['form1'] !== undefined) {
        this.$refs['form1'].resetFields()
      }
      this.dialogFormVisible3 = true
    },
    submitAdd(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['材料', this.form1.材料名称]
          var Data = this.CreateData('11', '零件明细表_材料_判断是否存在', param)
          this.ExecDatabase(Data).then(response => {
            if (Number(response.data[0].条数) >= 1) {
              this.$message.warning('添加的材料已存在')
            } else {
              var param = []
              param[0] = ['材料', this.form1.材料名称]
              var Data = this.CreateData('12', '零件明细表_材料_新增', param)
              this.ExecDatabase(Data).then(response => {
                if (response.data[0].result === '1') {
                  this.$message.success('添加成功')
                  this.searchTable2()
                  this.dialogFormVisible3 = false
                } else {
                  this.$message.error('添加失败')
                }
              })
            }
          })
        }
      })
    },
    updateMaterial(row) {
      if (this.$refs['form1'] !== undefined) {
        this.$refs['form1'].resetFields()
      }
      this.title1 = '编辑材料'
      this.form1.材料名称 = row.材料
      this.materialNumber = row.材料流水号
      this.dialogFormVisible3 = true
    },
    submitUpdate1(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['材料', this.form1.材料名称]
          param[1] = ['材料流水号', this.materialNumber]
          var Data = this.CreateData('12', 'PDM_零件明细表_材料_编辑', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('编辑成功')
              this.searchTable2()
              this.dialogFormVisible3 = false
            } else {
              this.$message.error('编辑失败')
            }
          })
        }
      })
    },
    deleteMaterial(row) {
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['材料流水号', row.材料流水号]
        var Data = this.CreateData('12', 'PDM_零件明细表_材料_作废', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.searchTable2()
          } else {
            this.$message.error('删除失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    callOff1(formName) {
      this.form1.材料名称 = ''
      this.dialogFormVisible3 = false
      this.$refs[formName].resetFields()
    },
    handleSizeChanges(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChanges(val) {
      this.pageCurrent = val
      this.searchTable()
    },
    handleSizeChanges1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      this.searchTable2()
    },
    handleCurrentChanges1(val) {
      this.pageCurrent1 = val
      this.searchTable2()
    }
  }
}
</script>
<style scoped>
  .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>
