<template>
  <div>
    <el-form
      ref="form"
      :model="form"
      class="el-form-box"
      label-width="160px"
    >
      <headerTitle title="基本信息"></headerTitle>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item labelWidth="100px" label="冲差单编码" prop="orderNo">
            <el-input
              clearable
              v-model="form.orderNo"
              disabled
              placeholder="自动生成"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
             labelWidth="100px"
            label="冲差类型"
            prop="type"
          >
            <DictSelection
              dictName="冲差类型"
              disabled
              clearable
              v-model="form.type"
            >
            </DictSelection>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item
            labelWidth="100px"
            label="冲差原因"
            prop="reason"
            disabled
          >
            <DictSelection
              dictName="冲差原因"
              clearable
              v-model="form.reason"
              disabled
            >
            </DictSelection>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item labelWidth="100px" label="冲差方式" prop="method">
            <DictSelection
              dictName="冲差方式"
              disabled
              clearable
              v-model="form.method"
            >
            </DictSelection>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item
            labelWidth="100px"
            label="调整类型"
            prop="adjustType"
            disabled
          >
            <DictSelection
              dictName="调整类型"
              clearable
              v-model="form.adjustType"
              disabled
            >
            </DictSelection>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item labelWidth="100px" label="冲差范围" prop="rangeType">
            <DictSelection
              dictName="冲差范围"
              disabled
              clearable
              v-model="form.rangeType"
            >
            </DictSelection>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item labelWidth="100px" label="调整说明" prop="remark">
            <el-input
              clearable
              v-model="form.remark"
              type="textarea"
              rows="1"
              placeholder="请输入"
              disabled
            />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item labelWidth="100px" prop="files" label="附件">
            <fileMain v-model="form.files" type="view"></fileMain>
          </el-form-item>
        </el-col>
      </el-row>
      <headerTitle title="物品清单" style="margin-top: 30px"></headerTitle>
      <inventoryTableDetails
        ref="inventoryTableDetailsRef"
        :isDiscountTotalPrice="true"
        :isSelected="true"
      ></inventoryTableDetails>
      <headerTitle
        title="冲差信息"
        style="margin-top: 30px"
      ></headerTitle>
      <inventoryTable
        ref="inventoryTableRef"
      ></inventoryTable>
      <div style="margin-top: 20px;">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label-width="100px" label="总差异金额:" prop="differenceAmount">
              <el-input
                clearable
                v-model="form.differenceAmount"
                disabled
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label-width="100px" label="总金额:" prop="adjustAmount">
              <el-input
                clearable
                disabled
                v-model="form.adjustAmount"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label-width="100px" label="优惠后总金额:" prop="adjustDiscountAmount">
              <el-input
                clearable
                disabled
                type="number"
                v-model="form.adjustDiscountAmount"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
  </div>
</template>
<script>
  import { mapGetters } from 'vuex';
  import { getPunchSlipOrderInfo } from '@/api/bpm/components/saleManage/saleorder.js';
  // import fileMain from '@/components/addDoc/index.vue';
  import { relationTypeList } from '@/enum/dict.js';
  import inventoryTable from './inventoryTable.vue';
  import inventoryTableDetails from '@/BIZComponents/inventoryTableDetails.vue';
  import { reduce } from 'lodash';

  const defForm = {
    name: '',
    changeCode: '',
    file: [], //条件
    remark: '',
    type: '',
    describes: '',
    relationId: '',
    relationName: '',
    relationCode: '',
    relationType: ''
  };
  export default {
    components: { inventoryTable, inventoryTableDetails },
    computed: {
      ...mapGetters(['user'])
    },
    props: {
      businessId: {
        default: ''
      }
    },
    data() {
      return {
        form: {
          ...defForm
        }
      };
    },
    created() {
      this.getInfo(this.businessId);
    },
    methods: {
      //获取详情
      async getInfo(id) {
        let data = await getPunchSlipOrderInfo(id);
        if (data) {
          // console.log('data~~~~', reduce(data.originalList, (total, item) => total + item.amount, 0));
          const tempdata = {
            // ...data,
            totalPrice: reduce(data.originalList, (total, item) => total + item.totalPrice, 0),
            discountTotalPrice: reduce(data.originalList, (total, item) => total + item.discountTotalPrice, 0),
            productList: data.originalList
          }
          this.businessId = data.id;
          this.adjustData = data.detailList;
          this.form = data;
          console.log('tempdata~~~~', tempdata);
          this.$refs.inventoryTableDetailsRef &&
            this.$refs.inventoryTableDetailsRef.putTableValue(tempdata);
          this.$refs.inventoryTableRef && this.$refs.inventoryTableRef.putTableValue(data.detailList);
        }
      }
    }
  };
</script>
<style scoped lang="scss"></style>
