<template>
  <div>
    <xy-dialog ref="dialog" :width='70' :is-show.sync="isShow" type="form"
      :title="type === 'add' ? `新增${rukuTypeName}入库` : `编辑${rukuTypeName}入库`" :form="form" :rules="rules"
      @submit="submit">

      <template v-slot:caigouhetong v-if="form.rukuleixing=='采购'">
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>采购合同：
          </div>
          <div class="xy-table-item-content">
            <el-input type="text" @focus="isShowHt=true" v-model="form.caigouhetong" placeholder="请选择采购合同"
              style="width: 300px;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:caigouhetong v-if="form.rukuleixing=='请示'">
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>请示流程：
          </div>
          <div class="xy-table-item-content">
            <el-input type="text" @focus="isShowQs=true" v-model="form.qingshiliucheng" placeholder="请选择请示流程"
              style="width: 300px;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:gudingzichanbianhao>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>固定资产编号：
          </div>
          <div class="xy-table-item-content">
            <el-input type="text" v-model="form.gudingzichanbianhao" placeholder="请填写固定资产编号"
              style="width: 300px;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:rukushijian>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;">*</span>入库时间：
          </div>
          <div class="xy-table-item-content">
            <el-date-picker style="width: 300px;" v-model="form.rukushijian" type="date" placeholder="选择日期"
              value-format="yyyy-MM-dd">
            </el-date-picker>
          </div>
        </div>
      </template>
      <!-- <template v-slot:rukuleixing>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;">*</span>入库类型：
          </div>
          <div class="xy-table-item-content">
            <el-select v-model="form.rukuleixing" style="width: 300px;" placeholder="请选择">
              <el-option v-for="item in lexingoptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
        </div>
      </template> -->
      <template v-slot:rukucangku>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>入库仓库：
          </div>
          <div class="xy-table-item-content">
            <el-select v-model="form.rukucangku" filterable style="width: 300px;" placeholder="请选择入库仓库">
              <el-option v-for="item in cangkuList" :key="item.cangkumingcheng" :label="item.cangkumingcheng"
                :value="item.cangkumingcheng">
              </el-option>
            </el-select>
          </div>
        </div>
      </template>

      <template v-slot:jingbanren>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;">*</span>经办人：
          </div>
          <div class="xy-table-item-content">
            <el-input v-model="form.jingbanren" placeholder="请输入经办人" clearable style="width: 300px;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:jilurenyuan>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;">*</span>记录人员：
          </div>
          <div class="xy-table-item-content">
            <el-input v-model="form.jilurenyuan" placeholder="请输入记录人员" clearable style="width: 300px;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:baoguanrenyuan>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>保管人员：
          </div>
          <div class="xy-table-item-content">
            <el-input v-model="form.baoguanrenyuan" placeholder="请输入保管人员" clearable style="width: 300px;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:beizhu>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>备注：
          </div>
          <div class="xy-table-item-content">
            <el-input type="textarea" v-model="form.beizhu" placeholder="请输入备注" clearable
              style="width: 300px;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:rukumingxi>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>入库明细 ：
          </div>
          <div class="xy-table-item-content">
            <Button type="primary" icon="md-add" style="margin-bottom: 10px" @click="isShowMingxi=true">新增入库明细</Button>
            <Button type="primary" icon="md-add" style="margin-bottom: 10px;margin-left: 10px" @click="importsRuku">导入</Button>
            <xy-table style="width: 60%" :height="260" :is-page="false" :list="mingxiList" :table-item="mingxiTable">
              <template v-slot:btns>
                <el-table-column label="操作" width="90" header-align="center" align="center">
                  <template v-slot:default="scope">
                    <Button size="small" type="primary" ghost @click="mingxiList.splice(scope.$index, 1)">删除</Button>
                  </template>
                </el-table-column>
              </template>
            </xy-table>
          </div>
        </div>
      </template>
    </xy-dialog>



    <!-- 新增明细 -->
    <Modal v-model="isShowMingxi" width='600' title="新增明细" :loading='showLoading' @on-cancel='mingxiCancel'
      @on-ok="mingxiConfirm">
      <div class="mingxiwrap">
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;">*</span>物资编码：
          </div>
          <div class="xy-table-item-content" style="display: flex;align-items: center;">
            <el-input v-if="form.rukuleixing!='回库'" type="text" @focus="showWuzi" v-model="mingxiObj.wuzibianma"
              placeholder="请选择物资编码" style="width: 300px;"></el-input>
            <el-input v-if="form.rukuleixing=='回库'" @change='getKucunShow' ref='huikubianma' type="text"
              v-model="mingxiObj.wuzibianma" placeholder="请扫码获取回库物资编码" style="width: 300px;"></el-input>
            <Button @click='showWuzi("回库")' v-if="form.rukuleixing=='回库'" type="primary" icon="md-add"
              style="margin-left: 10px">选择</Button>
          </div>
        </div>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>资产名称：
          </div>
          <div class="xy-table-item-content">
            <el-input type="text" @focus="showWuzi" v-model="mingxiObj.zichanmingcheng" placeholder="请选择资产名称" disabled
              style="width: 300px;"></el-input>
          </div>
        </div>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>规格型号：
          </div>
          <div class="xy-table-item-content">
            <el-input type="text" v-model="mingxiObj.guigexinghao" placeholder="请选择规格型号" disabled
              style="width: 300px;"></el-input>
          </div>
        </div>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>物资类型：
          </div>
          <div class="xy-table-item-content">
            <el-input type="text" v-model="mingxiObj.wuzileixing" placeholder="请选择物资类型" disabled
              style="width: 300px;"></el-input>
          </div>
        </div>
        <div class="xy-table-item" v-if="form.rukuleixing!='回库'">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>物资分类：
          </div>
          <div class="xy-table-item-content">
            <el-input type="text" v-model="mingxiObj.fenlei" placeholder="请选择物资分类" disabled
              style="width: 300px;"></el-input>
          </div>
        </div>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>计量单位：
          </div>
          <div class="xy-table-item-content">
            <el-input type="text" v-model="mingxiObj.jiliangdanwei" placeholder="请选择计量单位" disabled
              style="width: 300px;"></el-input>
          </div>
        </div>
        <div class="xy-table-item" v-if="form.rukuleixing=='回库'">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>在库数量：
          </div>
          <div class="xy-table-item-content">
            <el-input type="text" v-model="mingxiObj.zaikushuliang" placeholder="请选择计量单位" disabled
              style="width: 300px;"></el-input>
          </div>
        </div>
        <div class="xy-table-item" v-if="mingxiObj.wuzileixing=='一类一码'">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;"></span>入库批次：
          </div>
          <div class="xy-table-item-content">
            <el-select v-model="mingxiObj.rukupici" ref='piciref' v-if="form.rukuleixing!='回库'" style="width: 300px;"
              filterable clearable allow-create default-first-option placeholder="请选择或新增入库批次">
              <el-option v-for="item in rukupiciList" :key="item.value" :label="item.value" :value="item.value">
              </el-option>
            </el-select>
            <el-input v-else type="text" v-model="mingxiObj.rukupici" disabled placeholder="请输入入库批次"
              style="width: 300px;"></el-input>
          </div>
        </div>

        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;">*</span>入库数量：
          </div>
          <div class="xy-table-item-content">
            <el-input type="text" v-model="mingxiObj.rukushuliang" placeholder="请填写入库数量"
              style="width: 300px;"></el-input>
          </div>
        </div>

      </div>

    </Modal>
    <!-- 选择物资编号 -->
    <Modal v-model="isShowWuzi" title="物资选择">
      <div class="searchCompanys">
        <el-input type="text" @keyup.enter.native="getList" v-model="keyword" placeholder="请输入关键词查找"></el-input>
        <el-button type="primary" @click="getList">查询</el-button>
      </div>
      <Table highlight-row ref="currentRowTable" :columns="wuziColumns" :data="showList"
        @on-current-change="wuziSelect" />
      <Page :current="wuziPageIndex" :total="showTotal" simple
        style="padding-top: 14px;display: flex;justify-content: center;" @on-change="wuziPageChange" />
    </Modal>

    <!-- 选择采购合同 -->
    <Modal v-model="isShowHt" title="合同选择" width='70%' @on-cancel='htCancel' @on-ok='htComfirm'>
      <div class="searchCompanys">
        <el-input type="text" @keyup.enter.native="getHt" v-model="htkeyword" placeholder="请输入关键词查找"></el-input>
        <el-button type="primary" @click="getHt">查询</el-button>
      </div>
      <Table highlight-row ref="currentRowTable" :columns="htColumns" :data="htList" @on-current-change="htSelect" />
      <Page :current="htPageIndex" :total="htTotal" simple
        style="padding-top: 14px;display: flex;justify-content: center;" @on-change="htPageChange" />
    </Modal>
    <!-- 选择请示流程 -->
    <Modal v-model="isShowQs" title="请示选择" width='70%' @on-cancel='qsCancel' @on-ok='qsComfirm'>
      <div class="searchCompanys">
        <el-input type="text" @keyup.enter.native="getQs" v-model="qskeyword" placeholder="请输入关键词查找"></el-input>
        <el-button type="primary" @click="getQs">查询</el-button>
      </div>
      <Table highlight-row ref="currentRowTable" :columns="qsColumns" :data="qsList" @on-current-change="qsSelect" />
      <Page :current="qsPageIndex" :total="qsTotal" simple
      style="padding-top: 14px;display: flex;justify-content: center;" @on-change="qsPageChange" />
    </Modal>

    <detailContract ref='detailContract'></detailContract>
    <imports :table-name="importstableName" :istrueimport='false' :form-info="importForm" ref="imports"
      @importdata='getimportData'></imports>

  </div>
</template>

<script>
  import {
    save,
    index,
    show
  } from "@/api/system/baseForm.js"
  import {
    index as getContract,
    getQingShi,
    getOatoken
  } from "@/api/contract.js"
  import {
    Message
  } from 'element-ui'
  import detailContract from "../component/detailContract.vue"
  import imports from "@/views/component/imports.vue"
  import {
    index as fieldIndex
  } from "@/api/system/customFormField";
  export default {
    components: {
      detailContract,
      imports
    },
    data() {
      return {
        isShow: false,
        type: 'add',
        id: '',
        rukuType: '',
        authName:'',
        rukuTypeName: '盘点',
        tableName: 'stocks',
        importstableName: 'stocks_items',
        customFormId: 8,
        importForm: [],
        cangkuList: [],
        lexingoptions: [{
          label: '盘点',
          value: '盘点'
        }, {
          label: '采购',
          value: '采购'
        }, {
          label: '回库',
          value: '回库'
        }],
        rukupiciList: [],
        form: {
          caigouhetong: '',
          gudingzichanbianhao: '',
          rukushijian: '',
          // caigouhetong:'',
          rukuleixing: '',
          rukucangku: '',
          jingbanren: "",
          jilurenyuan: '',
          baoguanrenyuan: '',
          beizhu: '',
          rukumingxi: ''
        },
        rules: {
          rukushijian: [{
            required: true,
            message: '请选择入库时间'
          }],
          // caigouhetong: [{
          //   required: true,
          //   message: '请选择采购合同'
          // }],
          jingbanren: [{
            required: true,
            message: '请填写经办人'
          }],
          jilurenyuan: [{
            required: true,
            message: '请填写记录人员'
          }]
        },
        hetongoptions: [],
        isShowMingxi: false,
        showLoading: true,
        mingxiObj: {
          wuzibianma: '',
          rukushuliang: ''
        },
        mingxiObjBefore: {},
        mingxiList: [],
        mingxiIndex: '',
        mingxiTable: [{
            label: "物资编码",
            prop: "wuzibianma",
            width: 180
          },
          {
            label: "资产名称",
            prop: "zichanmingcheng",
            width: 180,
          },
          {
            label: "规格型号",
            prop: "guigexinghao",
            width: 180,
          },
          {
            label: "物资类型",
            prop: "wuzileixing",
            width: 180
          },
          {
            label: "计量单位",
            prop: "jiliangdanwei",
            width: 180
          },
          {
            label: "入库数量",
            prop: "rukushuliang",
            width: 180
          }, {
            label: "入库批次",
            prop: "rukupici",
            width: 180
          }, {
            label: "在库数量",
            prop: "zaikushuliang",
            width: 180
          },
        ],
        // 物资
        isShowWuzi: false,
        wuziList: [],
        kucunList: [],
        showList: [],
        wuziPageIndex: 1,
        keyword: '',
        showTotal: 0,
        wuziTotal: 0,
        kucunTotal: 0,
        wuziColumns: [{
          width: 60,
          _isChecked: false,
          key: "isSelect",
          resizable: true,
          render: (h, params) => {
            return h('div', [
              h('Radio', {
                props: {
                  value: params.row.isSelect
                },
                on: {
                  'on-change': (e) => {
                    this.showList.forEach((items) => {
                      this.$set(items, 'isSelect', false)
                    });
                    this.showList[params.index].isSelect = e;
                  }
                }
              })
            ])
          }
        }, {
          title: '名称',
          key: 'names',
        }, {
          title: '物资类型',
          key: 'wuzileixing',
        }],
        // 合同
        isShowHt: false,
        htList: [],
        htPageIndex: 1,
        htkeyword: '',
        htTotal: 0,
        editHt: '',
        htColumns: [{
          width: 60,
          _isChecked: false,
          key: "isSelect",
          resizable: true,
          render: (h, params) => {
            return h('div', [
              h('Radio', {
                props: {
                  value: params.row.isSelect
                },
                on: {
                  'on-change': (e) => {
                    this.htList.forEach((items) => {
                      this.$set(items, 'isSelect', false)
                    });
                    this.htList[params.index].isSelect = e;
                  }
                }
              })
            ])
          }
        }, {
          title: '名称',
          key: 'name',
        }, {
          title: '类型',
          key: 'type_name',
          width: 100
        }, {
          title: '状态',
          key: 'status_name',
          width: 100
        }, {
          title: '查看',
          key: '',
          width: 100,
          render: (h, params) => {
            return h('span', {
              style: {
                color: '#0077CC',
                cursor: 'pointer'
              },
              on: {
                'click': (e) => {
                  console.log("click", params.row.id)
                  this.$refs['detailContract'].getDetail(params.row.id)
                  this.$refs['detailContract'].isShowDetail = true
                  // @click=","
                }
              }
            }, '查看详情')
          }
        }],
        //请示流程
        isShowQs:false,
        qsList: [],
        qskeyword: '',
        qsPageIndex: 1,
        qsTotal: 0,
        editQs: '',
        qsColumns: [{
          width: 60,
          _isChecked: false,
          key: "isSelect",
          resizable: true,
          render: (h, params) => {
            return h('div', [
              h('Radio', {
                props: {
                  value: params.row.isSelect
                },
                on: {
                  'on-change': (e) => {
                    this.qsList.forEach((items) => {
                      this.$set(items, 'isSelect', false)
                    });
                    this.qsList[params.index].isSelect = e;
                  }
                }
              })
            ])
          }
        }, {
          title: '名称',
          key: 'title',
        }, {
          title: '查看',
          key: '',
          width: 100,
          render: (h, params) => {
            return h('span', {
              style: {
                color: '#0077CC',
                cursor: 'pointer'
              },
              on: {
                'click': (e) => {
                  this.toQsFollow(params.row.belongs_id)
                  // @click=","
                }
              }
            }, '查看详情')
          }
        }],
      }
    },
    created() {
      this.getCangku()
    },
    methods: {
      // 导入入库明细
      importsRuku() {
        this.$refs['imports'].show()
        this.getField()
      },
      getimportData(e) {
        console.log("e", e)
        this.mingxiList = e
      },
      // 获取采购合同
      async getHt() {
        let res = await getContract({
          page_size: 10,
          page: this.htPageIndex,
          keyword: this.htkeyword,
          type: 2,
          status: 2
        })
        for (var m of res.list.data) {
          m.isSelect = false
          m.type_name = m.type == 1 ? '服务' : (m.type == 2 ? '货物' : (m.type == 3 ? '工程' : '其他'))
          m.status_name = m.status == 1 ? '待签订' : (m.status == 2 ? '已签订' : '')
        }
        console.log(res.list.data)
        this.htList = res.list.data
        this.htTotal = res.total
        // this.hetongoptions = res.data
      },
      htCancel() {
        this.htList.forEach((items) => {
          this.$set(items, 'isSelect', false)
        });
        this.form.caigouhetong = this.editHt
      },
      htSelect(e) {
        this.htList.forEach((items) => {
          this.$set(items, 'isSelect', false)
          if (items.id == e.id) {
            this.$set(items, 'isSelect', true)
          }
        });

      },
      htComfirm() {
        console.log("123")
        this.htList.forEach((items) => {
          if (items.isSelect == true) {
            this.form.caigouhetong = items.name
            this.editHt = items.name
          }
        });

      },
      htPageChange(e) {
        console.log("e", e)
        this.htPageIndex = e
        this.getHt()
      },
      // 获取请示流程
      async getQs() {
        let res = await getQingShi({
          table:'qingshi',
          page:this.qsPageIndex
          // page_size: 10,
          // page: this.htPageIndex,
          // keyword: this.htkeyword,
        })
        for (var m of res.data.flow.data) {
          m.isSelect = false
        }
        this.qsList = res.data.flow.data
        this.qsTotal = res.data.flow.total
        // this.hetongoptions = res.data
      },
      qsCancel() {
        this.qsList.forEach((items) => {
          this.$set(items, 'isSelect', false)
        });
        this.form.qingshiliucheng = this.editQs
      },
      qsSelect(e) {
        this.qsList.forEach((items) => {
          this.$set(items, 'isSelect', false)
          if (items.id == e.id) {
            this.$set(items, 'isSelect', true)
          }
        });

      },
      qsComfirm() {
        this.qsList.forEach((items) => {
          if (items.isSelect == true) {
            this.form.qingshiliucheng = items.title
            this.editQs = items.title
          }
        });
      },
      qsPageChange(e) {
        this.qsPageIndex = e
        this.getQs()
      },
      async toQsFollow(id){
        let res = await getOatoken()
        let url =
          `${process.env.VUE_APP_OA_URL}/admin/flow/view/${id}?oatoken=${res.oatoken}`
        let seeBuy = window.open(url, 'seeBuy','location=0')
      },
      // 物资明细 回库从库存中选 其他从物资档案
      mingxiConfirm() {
        setTimeout(() => {
          this.showLoading = false
          this.$nextTick(() => {
            this.showLoading = true
          })
        }, 500)

        if (this.mingxiObj.wuzibianma == '' || this.mingxiObj.rukushuliang == '') {
          Message({
            type: 'warning',
            message: '请填写完整数据'
          })
          this.showLoading = false
          return
        }
        if (this.mingxiIndex != '') {
          this.mingxiList[this.mingxiIndex - 1] = this.mingxiObj
        } else {
          this.mingxiList.push(this.mingxiObj)
        }
        this.mingxiObj = {
          wuzibianma: '',
          rukushuliang: ''
        }
        this.mingxiObjBefore = {}
        this.mingxiIndex = ''
        this.isShowMingxi = false
        this.showLoading = false
        this.showList = []
        this.showTotal = 0
        this.wuziPageIndex = 1
      },
      mingxiCancel() {
        this.mingxiObj = {
          wuzibianma: '',
          rukushuliang: ''
        }
        this.mingxiObjBefore = {}
        this.mingxiIndex = ''
        this.isShowMingxi = false
        this.showList = []
        this.showTotal = 0
        this.wuziPageIndex = 1
      },
      editMingxi(index) {
        const before = this.mingxiList[index]
        for (var m in this.mingxiList[index]) {
          this.mingxiObjBefore[m] = this.mingxiList[index][m]
        }
        this.mingxiObj = this.mingxiList[index]
        this.mingxiIndex = index + 1 // 为0时！=‘’为false
        this.isShowMingxi = true
      },
      showWuzi(type) {
        this.isShowWuzi = true
        if (type == '回库') {
          this.$nextTick(() => {
            this.$refs.huikubianma.focus()
          })
          this.getKucun()
        } else {
          this.getWuzi()
        }
      },
      getList() {
        if (this.form.rukuleixing == '回库') {
          this.getKucun()
        } else {
          this.getWuzi()
        }
      },
      async getWuzi() {
        let res = await index({
          page_size: 10,
          page: this.wuziPageIndex,
          table_name: 'material_infos',
          filter: [{
            "key": "zichanmingcheng",
            "op": "like",
            "value": this.keyword
          }]
        })
        for (var m of res.data) {
          m.names = m.wuzibianma + "--" + m.zichanmingcheng
          m.isSelect = false
        }
        this.showList = res.data
        this.showTotal = res.total
      },
      async getKucun() {
        let res = await index({
          page_size: 10,
          page: this.wuziPageIndex,
          table_name: 'inventorys',
          filter: [{
            "key": "zichanmingcheng",
            "op": "like",
            "value": this.keyword
          }]
        })
        for (var m of res.data) {
          m.names = m.wuzibianma + "--" + m.zichanmingcheng
          m.isSelect = false
        }
        this.showList = res.data
        this.showTotal = res.total
      },
      async getKucunShow(e) {
        console.log(e)
        let id = ''
        if (e) {
          id = e.split('-')[1]
          this.$nextTick(() => {
            this.$refs.huikubianma.blur()
          })
        } else {
          return
        }
        const res = await show({
          id: id,
          table_name: "inventorys"
        })
        this.mingxiObj.wuzibianma = res.wuzibianma
        this.mingxiObj.zichanmingcheng = res.zichanmingcheng
        this.mingxiObj.guigexinghao = res.guigexinghao
        this.mingxiObj.wuzileixing = res.wuzileixing
        this.mingxiObj.jiliangdanwei = res.jiliangdanwei
        this.mingxiObj.zaikushuliang = res.zaikushuliang
        this.mingxiObj.rukupici = res.rukupici
        this.mingxiObj.id = res.id
      },
      async getPici() {
        let res = await index({
          page_size: 999,
          page: 1,
          table_name: 'inventorys',
          filter: [{
            "key": "wuzibianma",
            "op": "eq",
            "value": this.mingxiObj.wuzibianma
          }]
        })
        this.rukupiciList = []
        for (var m of res.data) {
          this.rukupiciList.push({
            value: m.rukupici,
            label: m.rukupici
          })
        }
      },
      wuziSelect(e) {
        console.log(e)
        this.showList.forEach((items) => {
          this.$set(items, 'isSelect', false)
          if (items.id == e.id) {
            this.$set(items, 'isSelect', true)
          }
        });
        if (this.form.rukuleixing == '回库') {
          this.mingxiObj.wuzibianma = e.wuzibianma
          this.mingxiObj.zichanmingcheng = e.zichanmingcheng
          this.mingxiObj.guigexinghao = e.guigexinghao
          this.mingxiObj.wuzileixing = e.wuzileixing
          this.mingxiObj.jiliangdanwei = e.jiliangdanwei
          this.mingxiObj.zaikushuliang = e.zaikushuliang
          this.mingxiObj.rukupici = e.rukupici
          this.mingxiObj.id = e.id
        } else {
          this.mingxiObj.wuzibianma = e.wuzibianma
          this.mingxiObj.zichanmingcheng = e.zichanmingcheng
          this.mingxiObj.wuzileixing = e.wuzileixing
          this.mingxiObj.guigexinghao = e.guigexinghao
          this.mingxiObj.jiliangdanwei = e.jiliangdanwei
          this.mingxiObj.fenlei = e.fenlei
          if (this.mingxiObj.wuzileixing == '一类一码') {

            this.getPici()
          }

        }

      },
      wuziPageChange(e) {
        console.log("e", e)
        this.wuziPageIndex = e
        this.getList()
      },

      async getCangku() {
        let res = await index({
          page_size: 999,
          page: 1,
          table_name: 'materialstorages',
        })
        this.cangkuList = res.data
      },
      async getDetail() {
        const res = await show({
          id: this.id,
          table_name: this.tableName
        })
        this.form = {
          caigouhetong: res?.caigouhetong,
          gudingzichanbianhao: res?.gudingzichanbianhao,
          rukushijian: res?.rukushijian,
          rukuleixing: res?.rukuleixing,
          rukucangku: res.rukucangku,
          jingbanren: res?.jingbanren,
          jilurenyuan: res?.jilurenyuan,
          baoguanrenyuan: res?.baoguanrenyuan,
          beizhu: res?.beizhu,
          rukumingxi: ''
        }
        this.editHt = res?.caigouhetong
        this.mingxiList = res.id_stocks_items_stocks_id_relation
      },
      submit() {
        this.form.id_stocks_items_stocks_id_relation = this.mingxiList
        // return
        if (this.type === 'add') {
          save({
            table_name: this.tableName,
            ...this.form
          }).then(res => {
            Message({
              type: 'success',
              message: '新增成功'
            })
            this.isShow = false
            this.$emit('refresh')
          })
          return
        }
        if (this.type === 'editor') {
          save({
            id: this.id,
            table_name: this.tableName,
            ...this.form
          }).then(res => {
            Message({
              type: 'success',
              message: '编辑成功'
            })
            this.isShow = false
            this.$emit('refresh')
          })
        }
      },
      async getField() {
        const res = await fieldIndex({
          page: 1,
          page_size: 999,
          custom_form_id: this.customFormId,
          sort_name: 'sort',
          sort_type: 'asc',
        })
        if (res.data && res.data instanceof Array) {
          res.data.forEach(i => {
            if (i.field) {
              if (
                (i.edit_input === "checkbox" || i.edit_input === "radio" || i.edit_input === "select") &&
                i.parameter_id
              ) {
                getparameter({
                  id: i.parameter_id
                }).then((res) => {
                  i._paramters = res.detail ?? [];
                });
              }
              if (
                (i.edit_input === "checkbox" || i.edit_input === "radio" || i.edit_input === "select") &&
                i.link_table_name
              ) {
                index({
                  page: 1,
                  page_size: 999,
                  table_name: i.link_table_name,
                }).then((res) => {
                  i._paramters = res.data ?? [];
                });
              }
            }
          })
        }
        this.importForm = res.data
          ?.filter((i) => i.list_show)
          .map((i) => {
            return i
          })
      },
    },
    watch: {
      isShow(newVal) {
        if (newVal) {
          this.form.rukuleixing = this.rukuType
          this.rukuTypeName = this.rukuType == '回库' ? '归还' : this.rukuType
          if (this.rukuType == '采购') {
            this.getHt()
          }
          if (this.rukuType == '请示') {
            this.getQs()
          }
          if (this.type === 'editor') {
            this.getDetail()
          }
          if(this.type=='add'){
            this.form.jingbanren = this.authName
          }
        } else {
          this.id = ''
          this.type = ''
          this.authName = ''
          this.mingxiList = []
          this.$refs['dialog'].reset()
        }
      }
    }

  }
</script>

<style scoped lang="scss">
  .mingxiwrap {
    display: flex;
    flex-wrap: wrap;
  }

  .mingxiwrap .xy-table-item {
    margin-bottom: 10px
  }

  .searchCompanys {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
  }

  ::v-deep .searchCompanys .el-input {
    width: 82%
  }

  .xy-table-item-label {
    width: 160px;
  }

  .img__delete {
    transform: scale(0.8, 0.8);

    position: absolute;
    top: 4px;
    right: 4px;
  }

  ::v-deep .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  ::v-deep .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  ::v-deep .el-upload--picture-card {
    font-size: 28px;
    color: #8c939d;
    width: 80px !important;
    height: 80px !important;
    line-height: 80px !important;
    text-align: center;
  }

  ::v-deep .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 80px !important;
    height: 80px !important;
    line-height: 80px !important;
    text-align: center;
  }

  ::v-deep .avatar {
    width: 80px !important;
    display: block;
    border-radius: 6px;
  }

  ::v-deep .xy-table-item-label {
    width: 160px !important;
  }

  ::v-deep .el-date-editor .el-range-separator {
    width: auto !important;
  }

  ::v-deep .el-input-number .el-input__inner {
    text-align: left !important;
  }
</style>
