<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-business"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="form-content">
      <el-form
        ref="formInfo"
        :model="parameter"
        label-width="auto"
        label-position="right"
      >
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">基本信息</div>
          </div>
        </div>
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="对账单号" prop="isdCode">
              <el-input
                readonly
                v-model="parameter.isdCode"
                placeholder="自动申成对账单号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发起单位" prop="matCompanyName">
              <el-input
                clearable
                v-model="parameter.matCompanyName"
                placeholder="请输入发起单位"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发起人" prop="matUserName">
              <el-input
                clearable
                v-model="parameter.matUserName"
                placeholder="请输入发起人"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="发起人联系方式" prop="matCompanyPhone">
              <el-input
                clearable
                type="number"
                v-model="parameter.matCompanyPhone"
                placeholder="请输入发起人联系方式"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="对账单位" prop="vendorName">
              <el-input v-model="parameter.vendorName" placeholder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="收货单" prop="receiptId">
              <el-input
                v-model="parameter.receiptId"
                placeholder="请选择收货单"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="含税总金额" prop="totalAmount">
              <el-input
                v-model="parameter.totalAmount"
                readonly
                placeholder="由收货单自动计算"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="不含税总金额" prop="amount">
              <el-input
                v-model="parameter.amount"
                readonly
                placeholder="由收货单自动计算"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合计税额" prop="taxAmount">
              <el-input
                v-model="parameter.taxAmount"
                readonly
                placeholder="由收货单自动计算"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">物料信息</div>
          </div>
        </div>
        <el-table
          ref="singleTable"
          :data="parameter.isdDetail"
          style="width: 100%"
          border
          highlight-current-row
          :cell-style="{'text-align': 'center'}"
          :header-cell-style="{'text-align': 'center'}"
        >
          <el-table-column fixed type="index" width="55" label="序号" />
          <el-table-column
            label="企业物料编号"
            min-width="100"
            show-overflow-tooltip
            prop="matCode"
          >
          </el-table-column>
          <el-table-column
            label="平台物料编号"
            min-width="100"
            show-overflow-tooltip
            prop="matPlatcode"
          >
          </el-table-column>
          <el-table-column
            label="物料名称"
            min-width="80"
            show-overflow-tooltip
            prop="matName"
          >
          </el-table-column>
          <el-table-column
            label="物料牌号"
            min-width="100"
            show-overflow-tooltip
            prop="matMaterial"
          >
          </el-table-column>
          <el-table-column
            label="规格型号"
            min-width="80"
            show-overflow-tooltip
            prop="matSpec"
          >
          </el-table-column>
          <el-table-column
            label="计划编号"
            min-width="100"
            show-overflow-tooltip
            prop="planCode"
          >
          </el-table-column>
          <el-table-column label="计量单位" min-width="100" prop="matUnit">
          </el-table-column>
          <el-table-column label="收货数量" min-width="130" prop="isdQuantity">
          </el-table-column>
          <el-table-column label="税率(%)" min-width="110" prop="taxRate">
          </el-table-column>
          <el-table-column
            label="含税单价(元)"
            min-width="130"
            prop="taxInprice"
          >
          </el-table-column>
          <el-table-column
            label="含税金额(元)"
            min-width="130"
            prop="taxInvalue"
          >
          </el-table-column>
          <el-table-column
            label="不含税单价(元)"
            min-width="130"
            prop="isdPrice"
          >
          </el-table-column>
          <el-table-column
            label="不含税金额(元)"
            min-width="130"
            prop="isdAmount"
          >
          </el-table-column>
          <el-table-column label="税额(元)" min-width="110" prop="taxValue">
          </el-table-column>

          <el-table-column
            label="基础扩展"
            min-width="100"
            show-overflow-tooltip
            prop="matBaseExt"
          >
          </el-table-column>
          <el-table-column
            label="其他扩展"
            min-width="100"
            show-overflow-tooltip
            prop="matOtherExt"
          >
          </el-table-column>
          <el-table-column
            label="挂账时间"
            min-width="100"
            show-overflow-tooltip
            prop="pendingTime"
          >
          </el-table-column>
          <el-table-column
            label="收货地址"
            min-width="100"
            show-overflow-tooltip
            prop="unloadAddress"
          >
          </el-table-column>
          <el-table-column
            label="企业补充说明"
            min-width="110"
            prop="purNote"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            label="供货方补充说明"
            min-width="110"
            prop="vendorNote"
            show-overflow-tooltip
          >
          </el-table-column>
        </el-table>
      </el-form>
    </div>
    <div slot="footer" class="footer">
      <el-button @click="handleClose">{{ $t('domestic.cancel') }}</el-button>
    </div>
  </div>
</template>

<script>
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import reconciliationManagement from '@/api/BasicDataManagement/reconciliationManagement.js'
export default {
  name: 'statementManagementAddDialog',
  components: {Breadcrumb},
  props: {
    editData: Object,
  },
  data() {
    return {
      breadcrumbOpt: [{breadcrumbName: '对账单管理'}, {breadcrumbName: '新增'}],
      parameter: {},
      oldDetailslist: [],
      receiptList: [],
      vendorList: [],
    }
  },
  created() {
    if (this.$route.query.detailRows) {
      let row = JSON.parse(JSON.stringify(this.$route.query.detailRows))
      this.selectOne(row)
    }
    this.addModifyBtn()
    this.getTableData()
    this.getOutCompany()
  },
  mounted() {},
  methods: {
    selectOne(row) {
      reconciliationManagement.selectOne(row.id).then((res) => {
        console.log(res, '1111')
        this.parameter = res.data.value
        if (!this.parameter.isdDetail) {
          this.parameter.isdDetail = []
        }
      })
    },
    getCode() {
      this.$http
        .get('${portal}/sys/identity/v1/getNextIdByAlias?alias=dzgl_dzdh')
        .then((res) => {
          if (res.data.state) {
            this.parameter.isdCode = res.data.value
          }
        })
    },
    // 查询发货公司
    getOutCompany() {
      let params = {
        querys: [],
        pageBean: {
          page: -1,
          pageSize: -1,
        },
      }
      params.querys.push(
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'status',
          relation: 'AND',
          value: '3',
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'inManifestCompanyId',
          relation: 'AND',
          value: this.parameter.matCompanyId,
        }
      )
      this.$http
        .post('${portal}/bizReceipt/v1/pageVendorGroup', params)
        .then((res) => {
          if (res.data.state) {
            this.vendorList = res.data.value.rows
          }
        })
    },
    //编辑
    addModifyBtn() {
      if (this.$route.query.editRows) {
        this.breadcrumbOpt[1].breadcrumbName = '编辑'
        this.modifychoData(this.$route.query.editRows)
      } else {
        this.breadcrumbOpt[1].breadcrumbName = '新增'
        this.getCode()
      }
    },
    //获取修改回显数据
    modifychoData(val) {
      reconciliationManagement.selectOne(val.id).then((res) => {
        console.log(res)
        this.parameter = res.data.value
        if (!this.parameter.isdDetail) {
          this.parameter.isdDetail = []
        } else {
          this.oldDetailslist = JSON.parse(
            JSON.stringify(this.parameter.isdDetail)
          )
        }
      })
    },
    // 关闭//面包屑点击
    handleClose() {
      if (this.breadcrumbOpt[1].breadcrumbName === '编辑') {
        this.$router.push({
          name: 'confirmationStatement',
          params: {
            pageBean: this.$route.query.pageBean,
          },
        })
      } else {
        this.$router.push({
          name: 'confirmationStatement',
        })
      }
      this.parameter = {}
    },
  },
}
</script>

<style lang="scss" scoped>
// /deep/.el-row {
//   padding: 0 100px;
// }
/deep/.el-row {
  display: flex;
  justify-content: center;
}
.rows {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebebeb;
  margin-bottom: 16px;
  padding: 10px 0;
  .rows-left {
    margin-right: 10px;
    .rows-hr {
      width: 3px;
      height: 18px;
      background-color: #0e6eff;
      border-radius: 2px;
    }
  }
  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
    }
  }
}
</style>
