<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-bill"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="form-content" v-loading="loading">
      <div class="company-information">
        <el-form
          ref="formInfo"
          :model="parameter"
          label-position="right"
          label-width="auto"
        >
          <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="订单编码">
                <el-input
                  :readonly="true"
                  clearable
                  v-model="parameter.orderCode"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="采购方">
                <el-input
                  :readonly="true"
                  clearable
                  v-model="parameter.matCompanyName"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="供货方">
                <el-input
                  :readonly="true"
                  clearable
                  v-model="parameter.vendorName"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24"> </el-row>
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="不含税总金额(元)" prop="orderAmount">
                <el-input
                  clearable
                  v-model="parameter.orderAmount"
                  :readonly="true"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="含税总金额(元)" prop="taxInvalue">
                <el-input
                  clearable
                  v-model="parameter.taxInvalue"
                  :readonly="true"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="订单时间" prop="orderCreatedate">
                <el-input
                  :readonly="true"
                  clearable
                  v-model="parameter.orderCreatedate"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24"> </el-row>
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="合同名称" prop="contractName">
                <el-input
                  :readonly="true"
                  clearable
                  v-model="parameter.contractName"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="订单状态" prop="status">
                <el-tag v-if="parameter.status == 3">已确认</el-tag>
                <el-tag type="danger" v-if="parameter.status == 2"
                  >未确认</el-tag
                >
              </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.detailsList"
            style="width: 100%"
            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="100"
              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="100"
              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"
              show-overflow-tooltip
              prop="matUnit"
            >
            </el-table-column>
            <el-table-column
              label="预计数量"
              min-width="100"
              show-overflow-tooltip
              prop="matNum"
            >
            </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="unloadAddress"
            >
            </el-table-column>
            <el-table-column
              label="企业补充说明"
              min-width="120"
              prop="remarks"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              label="供货方补充说明"
              min-width="120"
              prop="vendorNote"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              label="挂账时间"
              min-width="100"
              show-overflow-tooltip
              prop="pendingTime"
            >
            </el-table-column>
            <el-table-column
              v-if="parameter.payMethod == 2"
              label="承兑时间"
              min-width="100"
              prop="acceptanceTime"
            >
            </el-table-column>
            <el-table-column
              label="含税单价(元)"
              min-width="120"
              show-overflow-tooltip
              prop="taxInprice"
            >
            </el-table-column>
            <el-table-column
              label="含税金额(元)"
              show-overflow-tooltip
              min-width="90"
              prop="taxInvalue"
            >
            </el-table-column>
            <el-table-column
              label="不含税单价(元)"
              min-width="120"
              show-overflow-tooltip
              prop="orderPrice"
            >
            </el-table-column>
            <el-table-column
              label="不含税金额(元)"
              min-width="110"
              show-overflow-tooltip
              prop="orderAmount"
            >
            </el-table-column>
            <el-table-column
              label="税率(%)"
              show-overflow-tooltip
              min-width="80"
              prop="taxRate"
            >
            </el-table-column>
            <el-table-column
              label="税额(元)"
              show-overflow-tooltip
              min-width="80"
              prop="taxValue"
            >
            </el-table-column>
          </el-table>
        </el-form>
      </div>
    </div>
    <div slot="footer" class="footer">
      <el-button @click="handleClose">{{ $t('domestic.cancel') }}</el-button>
      <el-button
        icon="el-icon-user"
        type="primary"
        plain
        size="small"
        @click="handleSure(row)"
        v-if="parameter.status == 2"
        >同意订单</el-button
      >
      <el-button
        icon="el-icon-user"
        type="danger"
        plain
        size="small"
        @click="handleReject(row)"
        v-if="parameter.status == 2"
        >不同意订单</el-button
      >
    </div>
    <!-- 不同意订单弹窗 -->
    <el-dialog
      title="不同意订单"
      :visible.sync="dialogVisible"
      width="50%"
      v-loading="loading"
      :before-close="dialogBeforeClose"
    >
      <div>
        <el-form
          ref="forminfo"
          :model="form"
          :rules="rules"
          label-width="100px"
        >
          <el-form-item label="不同意原因" prop="reason">
            <el-input
              v-model="form.reason"
              clearable
              type="textarea"
              placeholder="请输入不同意原因"
            ></el-input>
          </el-form-item>
          <el-form-item label="附件上传">
            <div style="text-align: left;">
              <el-upload
                class="upload-demo"
                ref="upload"
                :headers="headers"
                :action="action"
                :file-list="form.fileList"
                :multiple="false"
                :on-progress="handleProgress"
                accept=".png,.jpg,.jpeg,.xlsx,.xls,.pdf,.docx,.doc,.zip,.rar"
                :show-file-list="false"
                :on-success="handleSuccess"
              >
                <el-button
                  icon="el-icon-upload"
                  slot="trigger"
                  style="width: 100px !important;"
                  size="small"
                  type="primary"
                  >上传文件</el-button
                >
              </el-upload>
              <el-table
                class="down"
                :data="form.fileList"
                border
                stripe
                style="width: 100%; margin-top: 20px"
              >
                <el-table-column prop="name" label="文件名称"></el-table-column>
                <el-table-column prop="size" label="文件大小">
                  <template slot-scope="scope">
                    <span>{{ scope.row.fileSize }}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="createTime" label="上传时间">
                  <template slot-scope="scope">
                    <div>
                      {{ scope.row.createTime }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="150px" label="操作">
                  <template slot-scope="scope">
                    <el-button size="small" type="text">
                      <a
                        target="_blank"
                        @click="downloadFile(scope.row.name, scope.row.url)"
                        >下载</a
                      >
                    </el-button>
                    <el-button
                      size="small"
                      type="text"
                      @click="deleteHandle(scope.$index)"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer">
        <el-button @click="dialogBeforeClose">取 消</el-button>
        <el-button type="primary" :loading="loadingBtn" @click="saveReject"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import utils from '@/utils.js'
import purchaseOrder from '@/api/BasicDataManagement/purchaseOrder.js'
import {mapState} from 'vuex'
export default {
  name: 'orderConfirmationDetail',
  components: {Breadcrumb},
  data() {
    return {
      breadcrumbOpt: [{breadcrumbName: '订单确认'}, {breadcrumbName: '详情'}],
      parameter: {},
      dialogVisible: false,
      loadingBtn: false,
      loading:false,
      form: {
        reason: '',
        fileList: [],
      },
      rules: {
        reason: [
          {
            required: true,
            message: '请输入原因',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  created() {
    this.parameter = this.$route.query.detailRows
    this.detail(this.parameter)
  },
  mounted() {},
  methods: {
    handleSure() {
      this.$confirm('是否确认订单吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.$http
          .post(
            '${portal}/bizPurchaseOrder/v1/updateStatus?ids=' +
              this.parameter.id +
              '&status=3'
          )
          .then((res) => {
            if (res.data.state) {
              this.$message.success('确认订单成功！')
              this.$router.go(-1)
            }
          })
      })
    },
    // 文件状态改变时的钩子，添加文件、上传成功和上传失败时都会被调用,function(file, fileList)
    handleSuccess(res, file, fileList) {
      this.loading = false
      this.form.fileList.push(res.value)
    },
    handleProgress() {
      this.loading = true
    },
    handleReject(row) {
      this.dialogVisible = true
    },
    dialogBeforeClose() {
      this.form = {}
      this.dialogVisible = false
      this.loadingBtn = false
    },
    // 关闭//面包屑点击
    handleClose() {
      this.$router.push({
        name: 'orderConfirmation',
        params: {
          pageBean: this.$route.query.pageBean,
        },
      })
      this.parameter = {}
    },
    //详情
    detail(val) {
      if (val) {
        this.modifychoData(val)
      }
    },
    //获取详情
    modifychoData(val) {
      this.$http
        .post('${portal}/bizPurchaseOrder/v1/selectOne?id=' + val.id)
        .then((res) => {
          if (res.data.state) {
            this.parameter = res.data.value
          }
        })
    },
    // 不同意保存
    saveReject() {
      this.$refs.forminfo.validate((valid) => {
        if (valid) {
          this.loadingBtn = true
        }
      })
    },
  },
  computed: {
    ...mapState({
      headers: (state) => {
        return {Authorization: `Bearer ${state.login.currentUser.token}`}
      },
      action: function () {
        return window.context.portal + '/biz/universal/v1/minioUpload'
      },
    }),
  },
}
</script>
  <style lang="scss" scoped>
::v-deep .el-form-item__label {
  width: 80px;
  font-size: 14px;
  color: #828282;
  font-weight: 500;
}
::v-deep .el-form-item {
  margin-bottom: 10px;
}
.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;
      border-radius: 2px;
    }
  }

  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
    }
  }
}
</style>
  