<template>
  <div class="bg-in-stock">
    <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="report_time" class="change-form-item">
        <span v-if="type == 'detail'">{{ goodsInventoryAddForm.report_time }}</span>
        <el-date-picker v-else v-model="goodsInventoryAddForm.report_time" value-format="yyyy-MM-dd HH:mm:ss"
          type="datetime" :disabled="type === 'detail' || type === 'audit' || type === 'edit'" placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="所属部门" prop="dept_id" class="change-form-item">
        <el-cascader v-model="goodsInventoryAddForm.dept_id" :options="deptList"
          :disabled="type === 'detail' || type === 'audit'" :props="{
            label: 'name',
            value: 'id',
            emitPath: false,
            checkStrictly: true
          }" clearable @change="changewarehouseList"></el-cascader>
      </el-form-item> -->
      <el-form-item label="仓库" prop="warehouse_id" class="change-form-item">
        <span v-if="type == 'detail'">{{ getWarehouse(goodsInventoryAddForm.warehouse_id) }}</span>
        <el-select v-else v-model="goodsInventoryAddForm.warehouse_id" @change="cleanGoodsList"
          :disabled="type === 'detail' || type === 'audit' || type === 'edit'">
          <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="damage_type_value" class="change-form-item">
        <span v-if="type == 'detail'">{{ getRoleSplit(goodsInventoryAddForm.damage_type_value) }}</span>
        <el-select v-else v-model="goodsInventoryAddForm.damage_type_value"
          :disabled="type === 'detail' || type === 'audit' || type === 'edit'">
          <el-option v-for="item in roleSplit" :key="item.label" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="制单人" prop="creator_id" class="change-form-item">
        <span v-if="type == 'detail'">{{ getadminList(goodsInventoryAddForm.creator_id) }}</span>
        <el-select v-else v-model="goodsInventoryAddForm.creator_id"
          :disabled="type === 'detail' || type === 'audit' || type === 'edit'" @change="changeCreator">
          <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="report_desc" class="change-form-item" style="width: 61%;">
        <span v-if="type == 'detail'">{{ goodsInventoryAddForm.report_desc }}</span>
        <el-input v-else style="flex: 1;" v-model="goodsInventoryAddForm.report_desc" type="textarea"
          :disabled="type === 'detail' || type === 'audit' || type === 'edit'" :autosize="{ minRows: 3, maxRows: 4 }"
          placeholder="请输入报损说明"></el-input>
      </el-form-item>
      <div class="mx">
        <h3>报损商品明细</h3>
        <el-button v-if="type !== 'edit' && type !== 'audit' && type !== 'detail'" class="button" size="mini"
          type="primary" @click="scanCode">录入SKU</el-button>
        <el-button v-if="type !== 'detail'" class="button" size="mini" type="primary"
          @click="handleSelectWarehouseEntryBatch">选择</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' }" style="width: 100%; margin-top: 20px;">
            <!-- <el-table-column label="入库单号">
              <template slot-scope="scope">
                {{ scope.row.stock_sn }}
              </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>{{ scope.row.product_vo.sku }}</span>
              </template>
            </el-table-column>
            <el-table-column label="序列号" v-if="sn_code_list">
              <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.usable_stock }}
              </template>
            </el-table-column>
            <!-- <el-table-column label="调整类型">
              <template slot-scope="scope">
                <el-select :disabled="type === 'detail' || type === 'audit'" v-model="scope.row.type" placeholder="请选择调整类型">
                  <el-option label="增加" :value="0" />
                  <el-option label="减少" :value="1" />
                </el-select>
              </template>
            </el-table-column> -->
            <el-table-column label="报损数量">
              <template slot-scope="scope">
                <span v-if="type == 'edit'">{{ scope.row.num }}</span>
                <el-input v-else v-model="scope.row.report_num" type="number" :min="0" :maxlength="20"
                  :disabled="type === 'detail' || type === 'audit'"></el-input>
              </template>
            </el-table-column>
            <!--  <el-table-column label="录入数量" >
              <template slot-scope="scope">
                <span>{{ scope.row.report_num }}</span>
              </template>
            </el-table-column> -->
            <!-- <el-table-column label="调整说明">
              <template slot-scope="scope">
                <el-input v-model="scope.row.report_remark" :min="0" :maxlength="50"
                  :disabled="type === 'detail' || type === 'audit'"></el-input>
              </template>
            </el-table-column> -->
            <el-table-column label="操作" v-if="type !== 'detail' && type !== 'audit' && type !== 'edit'">
              <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="primary" @click="handlePassGoodsInventoryLoss()">审核通过
      </el-button>
      <el-button v-if="type === 'audit'" type="danger" @click="dialogVisible = true">审核驳回
      </el-button> -->
      <el-button v-if="type !== 'edit' && type !== 'audit' && type !== 'detail'" type="primary"
        @click="submitGoodsInventoryAddForm">保存
      </el-button>
      <el-button v-if="type === 'edit'" type="primary" @click="submitcont">审核
      </el-button>
      <el-button v-if="type === 'edit'" type="primary" @click="submitreject">驳回
      </el-button>
      <el-button @click="printIng" v-if="type == 'detail'">打印</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" inline label-width="60px">
        <el-row>
          <el-col :span="18">
            <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-col>
          <el-col :span="18">
            <el-form-item label="序列号:" prop="sn_code">
              <el-input v-model="sn_code" ref="sn_input" @keyup.enter.native="toSnCode()" :minlength="0"
                :maxlength="100"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleRejectGoodsExchange()">确 定</el-button> -->
      </span>
    </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">
          <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="handleRejectGoodsInventoryLoss()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { Foundation, RegExp } from '~/ui-utils'
import * as API_GoodsInventoryLossLoss from '@/api/goodsInventoryLoss'
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() {
    const checkPrice = (rule, value, callback) => {
      if (!value && value !== 0) {
        return callback(new Error('调整金额不能为空'))
      } else if (!RegExp.money.test(value)) {
        callback(new Error('请输入正整数或者两位小数'))
      } else if (parseFloat(value) > 99999999) {
        callback(new Error('调整金额设置超过上限值'))
      } else {
        callback()
      }
    }
    return {
      adminList: [],
      dialogVisible: false,
      warehouseList: [],
      deptList: [],
      deptListAll: [],
      roleSplit: [],
      id: '',
      type: '',
      /** 出库单表单*/
      goodsInventoryAddForm: {
        product_list: [],
        creator_id: ''
      },
      /** 校验规则 */
      goodsInventoryAddFormRule: {
        warehouse_id: { required: true, message: '请选择报仓库', trigger: 'change' },
        damage_type_value: { required: true, message: '请选择报损类型', trigger: 'change' },
        /* report_desc: this.MixinRequired('请填写报损说明'), */
        dept_id: { required: true, message: '请选择所属部门', trigger: 'change' },
        creator_id: { required: true, message: '请选择制单人', trigger: 'change' }
      },
      warehouseProduct: null,
      scanDialogVisible: false,
      sn_code: "",
      sku: "",
      sn_code_list: [],
      index: "",
      scanGoodsForm: {},
    }
  },
  computed: {
    ...mapGetters(['user'])
  },
  mounted() {
    if (this.$route.name === 'goodsInventoryLossEdit') {
      console.log(112);
      this.type = 'edit'
    } else if (this.$route.name === 'goodsInventoryLossAudit') {
      this.type = 'audit'
    } else if (this.$route.name === 'goodsInventoryLossReturn') {
      this.type = 'return'
    } else if (this.$route.name === 'goodsInventoryLossAdd') {
      this.type = 'add'
      this.goodsInventoryAddForm.creator_id = this.user.uid
      this.goodsInventoryAddForm.dept_id = this.user.dept_id
      this.GET_WarehouseList({ dept_id: this.user.dept_id })
      /* this.$set(this.goodsInventoryAddForm, 'report_time', new Date().getTime()) */
    } else if (this.$route.name === 'goodsInventoryLossDetail') {
      this.type = 'detail'
    }
    if (this.$route.params.id) {
      this.id = this.$route.params.id
      this.GET_goodsInventoryAddDetail()
    }
    this.GET_DeptList()
    this.GET_DictDataInfo()
    this.GET_WarehouseList({ dept_id: this.user.dept_id })
    this.GET_AdministratorList()
  },
  methods: {
    /* 驳回 */
    submitreject() {
      this.$refs['goodsInventoryAddForm'].validate(valid => {
        if (valid) {
          const { id } = this.goodsInventoryAddForm
          const params = this.MixinClone(this.goodsInventoryAddForm)
          if (params.dept_id) {
            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
          }
          /* params.report_time = Math.floor(params.report_time / 1000) */
          if (params.damage_type_value) {
            params.damage_type_key = this.roleSplit.find(ware => ware.value === params.damage_type_value).label
          }
          if (params.creator_id) {
            params.creator = this.adminList.find(admin => admin.id === params.creator_id).real_name
          }
          params.status = 'CANCEL_HANDLE'
          params.product_list = params.product_list.map(item => {
            const query = {
              report_num: item.report_num,
              product_id: item.product_id,
              product_stock_id: item.product_stock_id
            }
            return query
          })
          API_GoodsInventoryLossLoss.submit(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: 'goodsInventoryLoss' })
          })
        }
      })
    },
    // 扫码出库
    scanCode() {
      this.scanDialogVisible = true;
      this.$nextTick(() => {
        this.$refs.input.focus();
      });
    },
    /* 出库扫码 */
    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) => {
          return (
            el.goods_vo.id === res.goods_id &&
            el.product_id === res.product_id &&
            el.product_vo.sku === res.product_vo.sku
          );
        });
        // 如果商品不存在，则添加到列表
        if (indexs === -1) {
          /*   // 检查是否有相同商品在product_list中
            const existingProduct = this.goodsInventoryAddForm.product_list.find(el => (
              el.goods_vo.id === res.goods_id &&
              el.product_id === res.product_id &&
              el.product_vo.sku === res.product_vo.sku
            ));
  
            if (!existingProduct) {
              this.$message.error('订单内没有该商品，请重新录入');
              this.$nextTick(() => {
                this.$refs.input.focus();
              });
              return; // 退出函数，不继续执行
            } */
          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].report_num += 1
          if (this.goodsInventoryAddForm.product_list[this.index].report_num == this.goodsInventoryAddForm.product_list[this.index].num) {
            this.scanDialogVisible = false;
          }
        }
      });
    },
    //扫序列号goodsInventoryAddForm.product_list[this.index].sn_code_list
    toSnCode() {
      if (this.sku == '') return this.$message.error('请录入正确的sku')
      API_GoodsExchange.getSnCode("out", this.sku, this.sn_code.replace(/\s+/g, '')).then((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) {
          this.goodsInventoryAddForm.product_list[this.index].sn_code_list.push(
            res
          );
        }
        this.goodsInventoryAddForm.product_list[this.index].report_num = this.goodsInventoryAddForm.product_list[this.index].sn_code_list.length
        const indexs = this.goodsInventoryAddForm.product_list.findIndex((el) => {
          return (
            el.goods_id === res.goods_id &&
            el.product_id === res.product_id &&
            el.product_vo.sku === res.sku
          );
        });
        this.goodsInventoryAddForm.product_list[this.index].id = this.goodsInventoryAddForm.product_list[indexs].id
        this.scanGoodsForm.bar_code = "";
        /* this.scanDialogVisible = false; */
        this.scanGoodsForm.bar_code = "";
        this.$nextTick(() => {
          this.$refs.input.focus();
        });


      });
    },

    /* 确认 */
    submitcont() {
      this.$refs['goodsInventoryAddForm'].validate(valid => {
        if (valid) {
          const { id } = this.goodsInventoryAddForm
          const params = this.MixinClone(this.goodsInventoryAddForm)
          if (params.dept_id) {
            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
          }
          /* params.report_time = Math.floor(params.report_time / 1000) */
          if (params.damage_type_value) {
            params.damage_type_key = this.roleSplit.find(ware => ware.value === params.damage_type_value).label
          }
          if (params.creator_id) {
            params.creator = this.adminList.find(admin => admin.id === params.creator_id).real_name
          }
          params.product_list = params.product_list.map(item => {
            const query = {
              report_num: item.report_num,
              product_id: item.product_id,
              product_stock_id: item.product_stock_id
            }
            return query
          })
          API_GoodsInventoryLossLoss.submit(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: 'goodsInventoryLoss' })
          })
        }
      })
    },

    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.roleSplit.find(type => type.value === 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() {

    },
    /** 修改报单人 */
    changeCreator(e) {
      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
      })
    },
    GET_DictDataInfo() {
      API_Setting.getDictDataInfo('es_stock_damage_report').then(response => {
        this.roleSplit = response
      })
    },
    /** 审核-通过 */
    handlePassGoodsInventoryLoss() {
      this.$confirm('确定通过吗？', '提示', { type: 'warning' }).then(() => {
        // const ids = this.multipleSelection.map(item => item.id)
        API_GoodsInventoryLossLoss.auditGoodsInventoryLoss(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: 'goodsInventoryLoss' })
        })
      }).catch(() => { })
    },
    /** 审核-拒绝 */
    handleRejectGoodsInventoryLoss() {
      this.$confirm('确定拒绝吗？', '提示', { type: 'warning' }).then(() => {
        // const ids = this.multipleSelection.map(item => item.id)
        API_GoodsInventoryLossLoss.auditGoodsInventoryLoss(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: 'goodsInventoryLoss' })
        })
      }).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)
          if (params.dept_id) {
            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
          }
          /* params.report_time = Math.floor(params.report_time / 1000) */
          if (params.damage_type_value) {
            params.damage_type_key = this.roleSplit.find(ware => ware.value === params.damage_type_value).label
          }
          if (params.creator_id) {
            params.creator = this.adminList.find(admin => admin.id === params.creator_id).real_name
          }
          params.product_list = params.product_list.map(item => {
            const query = {
              report_num: item.report_num,
              product_id: item.product_id,
              product_stock_id: item.id,
              sn_code_list: item.sn_code_list
            }
            return query
          })
          if (id) {
            API_GoodsInventoryLossLoss.editgoodsInventoryLossAdd(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: 'goodsInventoryLoss' })
            })
          } else {
            API_GoodsInventoryLossLoss.addgoodsInventoryLossAdd(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: 'goodsInventoryLoss' })
            })
          }
        }
      })
    },
    // 选择出库单
    async handleSelectWarehouseEntryBatch() {
      if (!this.goodsInventoryAddForm.warehouse_id) {
        this.$message.error('请先选择仓库！')
        return
      }
      const goodsData = await this.$EnwarehouseEntryBatch({
        goodsApi: `/admin/erp/warehouseOut/getGoodByWarehouse/${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
      this.goodsInventoryAddForm.product_list = goodsData.purchasePlans
      /*  .map(item => {
         const query = {
           stock_sn: item.warehouse_id,
           product_sn: item.product_sn,
           product_name: item.product_name,
           specification: item.warehouse_id,
           unit: item.product_unit,
           stock_num: item.remain_num,
           price: item.entry_price,
           cost_price: item.product_cost_price,
           tax_rate: item.tax_rate,
           batch_id: item.id,
           goods_id: item.goods_id,
           product_id: item.product_id,
           batch_sn: item.sn,
           category_id: item.category_id,
           category_name: item.category_name
         }
         return query
       }) */
    },
    /** 获取部门 */
    GET_DeptList() {
      API_Setting.getDeptList().then(response => {
        this.deptList = Foundation.buildTree(response, '0')
        this.deptListAll = response
      })
    },
    /** 获取详情页面数据 */
    GET_goodsInventoryAddDetail() {
      API_GoodsInventoryLossLoss.getGoodsInventoryLossInfo(this.id).then(response => {
        response.product_list.map(el => {
          el.num = el.report_num
          /* console.log(this.type); */
          /* if (this.type == 'edit') {
            el.report_num = 0
          } */

        })
        this.goodsInventoryAddForm = response
        /*  this.GET_WarehouseList({ dept_id: response.dept_id }) */
        /* this.goodsInventoryAddForm.report_time = Math.floor(this.goodsInventoryAddForm.report_time * 1000) */
        this.goodsInventoryAddForm.distribution_name = response.staff_name
        /*this.goodsInventoryAddForm.product_list = this.goodsInventoryAddForm.product_list.map(el => {
       item.product_specification = item.specification
        item.product_unit = item.unit
        item.remain_num = item.stock_num

          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
      })*/
      })
    }
  }
}
</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;
    }
  }
}

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

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