<template>
  <div class="bg-in-stock" v-loading="loading">
    <el-form ref="goodsInventoryAddForm" :model="goodsInventoryAddForm" :rules="goodsInventoryAddFormRule"
      label-width="120px" inline class="change-form">
      <h3 style="width: 100%;">盘点单</h3>
      <el-form-item label="盘点编号" prop="sn" v-if="type === 'edit' || type === 'detail'" class="change-form-item">
        <el-input v-model="goodsInventoryAddForm.sn" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="盘点时间" prop="inventory_time" class="change-form-item">
        <span v-if="id && type !== 'edit'">{{ goodsInventoryAddForm.inventory_time }}</span>
        <el-date-picker v-else v-model="goodsInventoryAddForm.inventory_time" value-format="yyyy-MM-dd HH:mm:ss"
          type="datetime" :disabled="type === 'detail' || type === 'audit' || type === 'check'" placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="仓库" prop="warehouse_id" class="change-form-item">
        <span v-if="id && type !== 'edit'">{{ getWarehouse(goodsInventoryAddForm.warehouse_id) }}</span>
        <el-select v-else v-model="goodsInventoryAddForm.warehouse_id" @change="handleChangeWareHouse"
          :disabled="type === 'detail' || type === 'audit' || type === 'check'">
          <el-option v-for="item in warehouseList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="盘点人" prop="inventory_person_id" class="change-form-item">
        <span v-if="id && type !== 'edit'">{{ getadminList(goodsInventoryAddForm.inventory_person_id) }}</span>
        <el-select v-else @change="forceUpdate" v-model="goodsInventoryAddForm.inventory_person_id"
          :disabled="type === 'detail' || type === 'audit' || type === 'check'">
          <el-option v-for="item in adminList" :key="item.id" :label="item.real_name" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="制单人" prop="creator_id" class="change-form-item">
        <span v-if="id && type !== 'edit'">{{ getadminList(goodsInventoryAddForm.creator_id) }}</span>
        <el-select v-else v-model="goodsInventoryAddForm.creator_id"
          :disabled="type === 'detail' || type === 'audit' || type === 'check'" @change="forceUpdate">
          <el-option v-for="item in adminList" :key="item.id" :label="item.real_name" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="盘点类型" prop="inventory_type" class="change-form-item">
        <span v-if="id && type !== 'edit'">{{ getRoleSplit(goodsInventoryAddForm.inventory_type) }}</span>
        <el-select v-else v-model="goodsInventoryAddForm.inventory_type" @change="handleChangeInventoryType($event)"
          :disabled="type === 'detail' || type === 'audit' || type === 'check'">
          <el-option v-for="item in typeList" :key="item.id" :label="item.label" :value="item.value" />
        </el-select>
        <!-- <el-cascader v-model="goodsInventoryAddForm.dept_id" :options="deptList"
          :disabled="type === 'detail' || type === 'audit' || type==='check'" :props="{
            label: 'name',
            value: 'id',
            emitPath: false,
            checkStrictly: true
          }" clearable @change="changewarehouseList"></el-cascader> -->
      </el-form-item>
      <div class="mx">
        <h3>商品明细</h3>
        <el-button class="button" size="mini" type="primary" v-if="type !== 'detail' && type !== 'check'"
          @click="scanCode">商品扫码</el-button>
        <el-button class="button" size="mini" type="primary" v-if="type !== 'detail' && type !== 'check'"
          @click="handleSelectWarehouseEntryBatch" :disabled="selectBtn">选择</el-button>
      </div>
      <div style="width: 100%; display: block;">
        <el-form-item style="width: 100%;">
          <el-table :data="goodsInventoryAddForm.product_list" border :cell-style="{ textAlign: 'center' }"
            :header-cell-style="{ textAlign: 'center' }" :loading="loading" style="width: 100%; margin-top: 20px;">
            <el-table-column label="库位号">
              <template slot-scope="scope">
                <el-popover placement="right" trigger="click" v-if="scope.row.area_stock_list">
                  <div>
                    <p v-for="item in scope.row.area_stock_list" :key="item.id">{{ item.warehouse_area_name }}</p>
                  </div>
                  <span slot="reference" v-if="scope.row.area_stock_list.length !== 0">{{
                    scope.row.area_stock_list[0].warehouse_area_name }}</span>
                </el-popover>
              </template>
            </el-table-column>
            <el-table-column label="商品编号">
              <template slot-scope="scope">
                <span v-if="id"> {{ scope.row.goods_vo.sn }}</span>
                <span v-else>{{ scope.row.goods_vo.sn }}</span>
              </template>
            </el-table-column>
            <el-table-column label="商品名称">
              <template slot-scope="scope">
                <span v-if="id">{{ scope.row.goods_vo.name }}</span>
                <span v-else>{{ scope.row.goods_vo.name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="sku">
              <template slot-scope="scope">
                <span v-if="!id"> {{ scope.row.product_vo.sku }}</span>
                <span v-else> {{ scope.row.product_vo.sku }}</span>
              </template>
            </el-table-column>
            <el-table-column label="序列号" width="160">
              <template slot-scope="scope">
                <div class="sn-code-container">
                  <span v-for="item in scope.row.sn_code_list" :key="item.id">
                    <p>{{ item.sn_code }}</p>
                  </span>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="product_vo.spec_name" label="规格型号">
              <!-- <template slot-scope="scope">
                <span v-if="!id">{{ scope.row.product_vo.spec_name.join("/") }}</span>
              <span v-else>{{ scope.row.product_vo.spec_name.join("/") }}</span>
              </template> -->
            </el-table-column>
            <el-table-column label="单位">
              <template slot-scope="scope">
                <span v-if="!id"> {{ scope.row.product_vo.unit }}</span>
                <span v-else> {{ scope.row.product_vo.unit }}</span>
              </template>
            </el-table-column>
            <el-table-column label="库存数量">
              <template slot-scope="scope">
                {{ scope.row.actual_stock }}
              </template>
            </el-table-column>
            <el-table-column label="盘点数量">
              <template slot-scope="scope">
                <span v-if="type === 'check'">{{ scope.row.inventory_num }}</span>
                <el-input v-else v-model="scope.row.inventory_num" type="number" :min="0" :maxlength="20"
                  :disabled="type === 'detail' || type === 'audit' || type === 'check'"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="差异">
              <template slot-scope="scope">
                {{ scope.row.inventory_num - scope.row.actual_stock || 0 }}
              </template>
            </el-table-column>
            <!-- <el-table-column label="备注">
              <template slot-scope="scope">
                {{ scope.row.remark }}
                <el-input v-model="scope.row.remark" :min="0" :maxlength="20" :disabled="true" v-show="false"></el-input>
              </template>
            </el-table-column> -->
            <el-table-column label="操作" v-if="type !== 'detail' && type !== 'audit' && type !== 'check'">
              <template slot-scope="scope">
                <el-button size="mini" type="danger"
                  @click="goodsInventoryAddForm.product_list.splice(scope.$index, 1)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </div>
    </el-form>
    <div class="footer">
      <!--    <el-button v-if="type === 'audit' && type !== 'detail' && type!=='check'" type="primary" @click="handlePassGoodsInventory()">通过
      </el-button>
      <el-button v-if="type === 'audit' && type !== 'detail' && type!=='check'" type="danger" @click="dialogVisible = true">驳回
      </el-button> -->
      <el-button v-if="type !== 'audit' && type !== 'detail' && type !== 'check'" type="primary"
        @click="submitGoodsInventoryAddForm">保存
      </el-button>
      <el-button @click="printIng" v-if="type == 'check'">打印</el-button>
      <el-button @click="$router.back()">返回
      </el-button>
    </div>
    <el-dialog title="扫码入库" :visible.sync="scanDialogVisible" width="30%" :close-on-click-modal="false">
      <el-form ref="scanGoodsForm" :model="scanGoodsForm" label-width="120px" inline>
        <!-- @blur="blurCode()" -->
        <el-form-item label="sku" prop="bar_code">
          <el-input v-model="scanGoodsForm.bar_code" ref="input" @keyup.enter.native="toSearch()" :minlength="0"
            :maxlength="100"></el-input>
        </el-form-item>
        <el-form-item label="序列号" prop="sn_code">
          <el-input ref="sn_input" v-model="sn_code" @keyup.enter.native="toSnCode()" :minlength="0"
            :maxlength="100"></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <el-form ref="goodsInventoryAddForm" :model="goodsInventoryAddForm" label-width="120px" inline
        style="width:900px">
        <el-form-item label="驳回原因" prop="reject_reason" required="true">
          <el-input v-model="goodsInventoryAddForm.reject_reason" type="textarea" :minlength="0"
            :maxlength="100"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleRejectGoodsInventory()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { Foundation, RegExp } from '~/ui-utils'
import * as API_GoodsInventory from '@/api/goodsInventory'
import * as API_GoodsExchange from "@/api/goodsExchange";
import * as API_Setting from '@/api/setting'
import * as API_BasicSetting from '@/api/basicSetting'
import * as API_Erp from '@/api/erp'
import * as API_Auth from '@/api/auth'
export default {
  name: 'goodsInventoryAdd',
  data() {
    return {
      // 列表loading状态
      loading: false,
      adminList: [],
      dialogVisible: false,
      warehouseList: [],
      deptList: [],
      deptListAll: [],
      id: '',
      type: '',
      /** 出库单表单*/
      goodsInventoryAddForm: {
        product_list: [],
        inventory_time: new Date(),
        inventory_person_id: '',
        creator_id: ''
      },
      /** 校验规则 */
      goodsInventoryAddFormRule: {
        inventory_person_id: { required: true, message: '请选择盘点人', trigger: 'change' },
        warehouse_id: { required: true, message: '请选择报损仓库', trigger: 'change' },
        dept_id: { required: true, message: '请选择所属部门', trigger: 'change' },
        creator_id: { required: true, message: '请选择制单人', trigger: 'change' }
      },
      warehouseProduct: null,
      typeList: [
      ],
      scanDialogVisible: false,//扫码窗口
      scanGoodsForm: {},
      sn_code: "",
      sn_code_list: [],
      index: "",
      selectBtn: false
    }
  },
  computed: {
    ...mapGetters(['user']),
    timeDefault() {
      var date = new Date();
      var s1 = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + (date.getDate()) + " " + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
      return s1;
    },
  },
  mounted() {
   /*  if (this.$route.name === 'goodsInventoryEdit') {
      this.type = 'edit'
    } else if (this.$route.name === 'goodsInventoryAudit') {
      this.type = 'audit'
    } else if (this.$route.name === 'goodsInventoryReturn') {
      this.type = 'return'
    } else */ if (this.$route.name === 'goodsInventoryAdd') {
      this.goodsInventoryAddForm.creator_id = this.user.uid
      this.goodsInventoryAddForm.inventory_person_id = this.user.uid
      this.goodsInventoryAddForm.dept_id = this.user.dept_id
      this.goodsInventoryAddForm.inventory_time = this.timeDefault;
    } else if (this.$route.name === 'goodsInventoryDetail') {
      this.type = 'detail'
    } else if (this.$route.name === 'goodsInventoryCheck') {
      this.type = 'check'
      this.id = this.$route.params.id
      this.GET_goodsInventoryAddDetail()
      this.GET_AdministratorList()
      this.GET_DeptList()
      this.GET_WarehouseList()
    } else if (this.$route.name === 'goodsInventoryEdit') {
      this.type = 'edit'
      this.goodsInventoryAddForm.creator_id = this.user.uid
      this.goodsInventoryAddForm.inventory_person_id = this.user.uid
      this.goodsInventoryAddForm.dept_id = this.user.dept_id
      this.goodsInventoryAddForm.inventory_time = this.timeDefault;
      this.id = this.$route.params.id
      this.GET_goodsInventoryAddDetail()
      this.GET_AdministratorList()
      this.GET_DeptList()
      this.GET_WarehouseList()
    }
    this.GET_AdministratorList()
    this.GET_DeptList()
    this.GET_WarehouseList()

  },
  methods: {
    handleChangeInventoryType(val) {
      this.goodsInventoryAddForm.product_list = []
      if (val === 'ALL_INVENTORY') {
        if (!this.goodsInventoryAddForm.warehouse_id) {
          this.$message.error('请先选择仓库！')
          return
        }
        this.loading = true
        API_GoodsInventory.getGoodByWarehouseInventory({ page: 1, size: 10000 }, this.goodsInventoryAddForm.warehouse_id).then(res => {
          res.records.map(el => {
            el.sn_code_list = []
          })
          this.goodsInventoryAddForm.product_list = res.records
          this.selectBtn = true
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      } else {
        this.selectBtn = false
      }

    },
    //扫序列号goodsInventoryAddForm.product_list[this.index].sn_code_list
    async toSnCode() {
      if (this.sku == '') return this.$message.error('请录入正确的sku')
      await API_GoodsExchange.getSnCode("inventory", this.sku, this.sn_code.replace(/\s+/g, '')).then(async (res) => {
        this.sn_code = "";
        // 假设res是一个对象，我们根据res的某个属性（如sn）来检查重复
        let exists = this.goodsInventoryAddForm.product_list[
          this.index
        ].sn_code_list.find(
          (item) => item.sn_code === res.sn_code && item.sku === res.sku
        );
        if (!exists) {
          if (this.id) {
            await API_GoodsExchange.skuRedis({
              send_order_id: this.id, item_id: this.goodsInventoryAddForm.product_list[
                this.index
              ].id, sku: res
            }).then(response => {
              this.goodsInventoryAddForm.product_list[this.index].sn_code_list.push(
                res
              );
            })
          } else {
            this.goodsInventoryAddForm.product_list[this.index].sn_code_list.push(
              res
            );
          }

        }
        /* this.goodsInventoryAddForm.product_list[this.index].sn_code_list.push(
          res
        ); */
        this.goodsInventoryAddForm.product_list[this.index].inventory_num =
          this.goodsInventoryAddForm.product_list[
            this.index
          ].sn_code_list.length;
        console.log(this.goodsInventoryAddForm.product_list, this.goodsInventoryAddForm.product_list[
          this.index
        ].sn_code_list.length);
        this.scanGoodsForm.bar_code = "";
        this.$nextTick(() => {
          this.$refs.input.focus();
        });
      });
    },
    /* 扫sku */
    toSearch() {
      API_GoodsExchange.getProduct(
        this.goodsInventoryAddForm.warehouse_id,
        this.scanGoodsForm.bar_code.replace(/\s+/g, '')
      ).then((res) => {
        res.sn_code_list = [];
        this.sku = res.product_vo.sku;
        // 查找当前商品是否已存在于列表中
        const indexs = this.goodsInventoryAddForm.product_list.findIndex(
          (el) => {
            console.log("Comparing with:", el);
            return (
              el.goods_id === res.goods_id &&
              el.product_id === res.product_id &&
              el.product_vo.sku === res.product_vo.sku
            );
          }
        );
        // 如果商品不存在，则添加到列表
        if (indexs === -1) {
          this.index = this.goodsInventoryAddForm.product_list.length;
          this.goodsInventoryAddForm.product_list.push(res);
        } else {
          this.index = indexs;
        }
        if (res.product_vo.have_sn) {
          this.$nextTick(() => {
            this.$refs.sn_input.focus();
          });
        } else {
          this.goodsInventoryAddForm.product_list[this.index].inventory_num += 1
         console.log( this.goodsInventoryAddForm.product_list[this.index].inventory_num)
          /* this.scanDialogVisible = false; */
        }
      });
    },
    // 扫码入库
    scanCode() {
      if (!this.goodsInventoryAddForm.warehouse_id) {
        this.$message.error("请选择仓库！");
        return;
      }
      if (!this.goodsInventoryAddForm.inventory_type) {
        this.$message.error("请选择盘点类型！");
        return;
      }
      this.scanDialogVisible = true;
      this.$nextTick(() => {
        this.$refs.input.focus();
      });
    },
    getadminList(value) {
      // Access orderTypeList directly from the component's data
      const type = this.adminList.find(type => type.id === value);
      return type ? type.real_name : '未知类型';
    },
    getRoleSplit(value) {
      // Access orderTypeList directly from the component's data
      const type = this.typeList.find(type => type.id === value);
      return type ? type.label : '未知类型';
    },
    getWarehouse(value) {
      // Access orderTypeList directly from the component's data
      const type = this.warehouseList.find(type => type.id === value);
      return type ? type.name : '未知类型';
    },
    // 打印功能
    printIng() {

    },
    /** 修改报单人 */
    forceUpdate() {
      this.$forceUpdate()
    },
    /** 清除已选商品明细 */
    cleanGoodsList() {
      // 切换部门或仓库需要清除已选对应仓库下的商品数据
      this.goodsInventoryAddForm.product_list = []
    },
    /** 获取人员列表 */
    GET_AdministratorList() {
      API_Auth.getAdministratorList({
        page_no: 1,
        page_size: 9999,
        user_state: 0
      }).then(response => {
        this.adminList = response.data
      })
    },
    /** 审核-通过 */
    handlePassGoodsInventory() {
      this.$confirm('确定通过吗？', '提示', { type: 'warning' }).then(() => {
        // const ids = this.multipleSelection.map(item => item.id)
        API_GoodsInventory.auditGoodsInventory(this.id, { status: 'PASS' }).then(() => {
          this.$message.success('已通过！')
          const { callback } = this.$route.params
          if (typeof callback === 'function') callback()
          this.$store.dispatch('delCurrentViews', {
            view: this.$route,
            $router: this.$router
          })
          this.$router.push({ name: 'goodsInventory' })
        })
      }).catch(() => { })
    },
    /** 审核-拒绝 */
    handleRejectGoodsInventory() {
      if (!this.goodsInventoryAddForm.reject_reason) {
        this.$message.error('请填写驳回原因！')
        return
      }
      this.$confirm('确定拒绝吗？', '提示', { type: 'warning' }).then(() => {
        // const ids = this.multipleSelection.map(item => item.id)
        API_GoodsInventory.auditGoodsInventory(this.id, { status: 'REJECT', reject_reason: this.goodsInventoryAddForm.reject_reason }).then(() => {
          this.$message.success('已拒绝！')
          const { callback } = this.$route.params
          if (typeof callback === 'function') callback()
          this.$store.dispatch('delCurrentViews', {
            view: this.$route,
            $router: this.$router
          })
          this.$router.push({ name: 'goodsInventory' })
        })
      }).catch(() => { })
    },
    changewarehouseList(e) {
      this.$set(this.goodsInventoryAddForm, 'warehouse_id', '')
      this.GET_WarehouseList({ dept_id: e })
      this.cleanGoodsList()
    },
    /** 获取仓库 */
    GET_WarehouseList(e) {
      API_BasicSetting.getWarehouseListAll().then(response => {
        this.warehouseList = response
      })
    },
    submitGoodsInventoryAddForm() {
      this.$refs['goodsInventoryAddForm'].validate(valid => {
        if (valid) {
          const { id } = this.goodsInventoryAddForm
          const params = this.MixinClone(this.goodsInventoryAddForm)
          /*  params.inventory_type = params.inventory_type.id */
          /* if (params.dept_id) {
            console.log(this.deptListAll);
            params.dept_name = this.deptListAll.find(dept => dept.id === params.dept_id).name
          } */
          if (params.warehouse_id) {
            params.warehouse_name = this.warehouseList.find(ware => ware.id === params.warehouse_id).name
          }
          if (params.creator_id) {
            params.creator = this.adminList.find(admin => admin.id === params.creator_id).real_name
          }
          if (params.inventory_person_id) {
            params.inventory_person = this.adminList.find(admin => admin.id === params.inventory_person_id).real_name
          }
          params.product_list = params.product_list.map(item => {
            const query = {
              diff_num: item.usable_stock - item.inventory_num,
              inventory_num: item.inventory_num * 1,
              product_name: item.product_name,
              product_sn: item.product_sn,
              product_id: item.product_id,
              specification: item.product_specification,
              unit: item.product_unit,
              remark: item.remark,
              product_stock_id: item.id,
              sn_code_list: item.sn_code_list
            }
            return query
          })
          if (this.id) {
            API_GoodsInventory.editgoodsInventoryAdd(this.id, params).then(response => {
              this.$message.success('修改成功！')
              const { callback } = this.$route.params
              if (typeof callback === 'function') callback()
              this.$store.dispatch('delCurrentViews', {
                view: this.$route,
                $router: this.$router
              })
              this.$router.push({ name: 'goodsInventory' })
            })
          } else {
            API_GoodsInventory.addgoodsInventoryAdd(params).then(() => {
              this.$message.success('添加成功！')
              const { callback } = this.$route.params
              if (typeof callback === 'function') callback()
              this.$store.dispatch('delCurrentViews', {
                view: this.$route,
                $router: this.$router
              })
              this.$router.push({ name: 'goodsInventory' })
            })
          }
        }
      })
    },
    // 选择出库单
    async handleSelectWarehouseEntryBatch() {
      if (!this.goodsInventoryAddForm.warehouse_id) {
        this.$message.error('请先选择仓库！')
        return
      }
      const goodsData = await this.$EnwarehouseEntryBatch({
        goodsApi: `/admin/erp/warehouseOut/getGoodByWarehouseInventory/${this.goodsInventoryAddForm.warehouse_id}`,
        warehouseList: this.warehouseList,
        selectedIds: this.id ? this.goodsInventoryAddForm.product_list && this.goodsInventoryAddForm.product_list.map(item => item.id) : this.goodsInventoryAddForm.product_list.map(item => item.id),
        purchasePlanApiParams: { warehouse_id: this.goodsInventoryAddForm.warehouse_id }
      })
      this.goodsInventoryAddForm.warehouse_id = goodsData.warehouse_id
      goodsData.purchasePlans.map(item => {
        item.sn_code_list = [];
      })

      this.goodsInventoryAddForm.product_list = goodsData.purchasePlans
      /* this.$set(this.goodsInventoryAddForm, 'product_list', goodsData.purchasePlans); */
      /* this.getlistProductLendNum(ProductLendNum, goodsData.purchasePlans) */
    },
    /* getlistProductLendNum(ProductLendNumList, warehouseEntryBatch) {
      API_GoodsInventory.getlistProductLendNum(ProductLendNumList).then(response => {
        warehouseEntryBatch.map(item => {
          response.forEach(item2 => {
            if (item.product_id === item2.product_id && item.warehouse_entry_sn === item2.stock_sn) {
              item.remark = item2.lend_num ? '借出' + item2.lend_num + (item.product_unit ? item.product_unit : '') : ''
            }
          })
        })
        this.goodsInventoryAddForm.product_list = warehouseEntryBatch
      })
    }, */
    /** 获取部门 */
    GET_DeptList() {
      API_Setting.getDeptList().then(response => {
        this.deptList = Foundation.buildTree(response, '0')
        this.deptListAll = response
      })
      API_Setting.getPage({ dictType: "inventory_type" }).then((res) => {
        this.typeList = res.data;
      });
    },
    /** 切换仓库 */
    handleChangeWareHouse(val) {
      this.goodsInventoryAddForm.product_list = []
    },
    /** 获取详情页面数据 */
    GET_goodsInventoryAddDetail() {
      API_GoodsInventory.getGoodsInventoryInfo(this.id).then(response => {
        /* response.product_list.map(el => {
            el.allow_sn=el.goods_vo.allow_sn
            el.bar_code=el.goods_vo.bar_code
            el.brand_id=el.goods_vo.brand_id
            el.brand_name=el.goods_vo.brand_name
            el.category_id=el.goods_vo.category_id
            el.category_ids=el.goods_vo.category_ids
            el.category_name=el.goods_vo.category_name
            el.cost_price=el.goods_vo.cost_price
            el.create_time=el.goods_vo.create_time
            el.creator=el.goods_vo.creator
            el.description=el.goods_vo.description
            el.en_name=el.goods_vo.en_name
            el.freight_template_id=el.goods_vo.freight_template_id
            el.goods_style=el.goods_vo.goods_style
            el.goods_unit=el.goods_vo.goods_unit
            el.goods_unit=el.goods_vo.goods_unit
            el.have_spec=el.goods_vo.have_spec
            el.hire_or_sail=el.goods_vo.hire_or_sail
            el.image=el.goods_vo.image
            el.image_list=el.goods_vo.image_list
            el.label_names=el.goods_vo.label_names
            el.market_enable=el.goods_vo.market_enable
            el.mkt_price=el.goods_vo.mkt_price
            el.name=el.goods_vo.name
            el.params_list=el.goods_vo.params_list
            el.price=el.goods_vo.price
            el.sn=el.goods_vo.sn
            el.sn_code=el.goods_vo.sn_code
            el.sort=el.goods_vo.sort
            el.update_time=el.goods_vo.update_time
            el.updater=el.goods_vo.updater
            el.usable_stock=el.goods_vo.usable_stock
            el.video=el.goods_vo.video
            return el
          }) */
        if (!response.product_list) {
          response.product_list = []
        }
        this.goodsInventoryAddForm = response
        this.GET_WarehouseList()
        this.goodsInventoryAddForm.distribution_name = response.staff_name
        if (this.goodsInventoryAddForm.product_list) {
          this.goodsInventoryAddForm.product_list = this.goodsInventoryAddForm.product_list.map(item => {
            item.inventory_num = item.inventory_num
            item.product_specification = item.specification
            item.product_unit = item.unit
            item.remain_num = item.stock_num
            return item
          })
        } else {
          this.goodsInventoryAddForm.product_list = []
        }

      })
    }
  }
}
</script>

<style type="text/scss" lang="scss" scoped>
/** 底部步骤 */
.footer {
  width: 100%;
  padding: 10px;
  bottom: 0px;
  text-align: center;
  z-index: 999;
}

.mx {
  display: flex;
  align-items: center;
  width: 100%;

  .button {
    margin-left: 10px;
  }
}

.change-form {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  flex-wrap: wrap;
  min-width: 900px;

  .change-form-item {
    width: 30%;
    margin: 0 10px 20px 0;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
  }

  /deep/ {
    .el-form-item__content {
      flex: 1;
      width: 100%;
    }

    .el-date-editor,
    .el-cascader,
    .el-select {
      width: 100%;
    }
  }
}

.bg-in-stock {
  background-color: #fff;
  margin: 10px;
  padding: 25px;
}

.goods-info {
  display: flex;

  .goods-name-box {
    text-align: left;

    .goods-name {
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
      line-height: 16px;
    }

    .specs {
      color: #999999;
    }
  }
}

.sn-code-container {
  max-height: 100px;
  /* 设置最大高度，超过这个高度将显示滚动条 */
  overflow-y: auto;
  /* 垂直方向上溢出时显示滚动条 */
}

/deep/ {
  .el-input--suffix .el-input__inner {
    padding-right: 10px;
  }

  .error-input {
    .el-input__inner {
      border: 1px solid red;
    }
  }
}
</style>
