<!-- 归还入库表单 -->
<template>
  <modal v-model="modal" :footer-hide="true" width="700px">
    <!--  表单主要内容  -->
    <div class="content">
      <div class="title">
        合同删除审批
      </div>
      <div class="sub-title border">
        <span>基本信息</span>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">申请人：</div>
          <div class="value">{{ data.userName  }}</div>
        </div>
        <div class="col">
          <div class="label">申请部门：</div>
          <div class="value">{{ data.deptName }}</div>
        </div>
        <div class="col">
          <div class="label">申请时间：</div>
          <div class="value">{{ data.createdTime  }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">删除原因：</div>
          <div class="value">{{ data.reason }}</div>
        </div>
      </div>
      <div class="sub-title border">
        <span>合同信息</span>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">申购单号：</div>
          <div class="value">{{ data.applyBillNo }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">合同编码：</div>
          <div class="value">{{ data.purchaseBillNo }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料编码：</div>
          <div class="value">{{ data.materialCode }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料名称：</div>
          <div class="value">{{ data.materialName }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">供应商：</div>
          <div class="value">{{ data.supplierName }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">采购数量：</div>
          <div class="value">{{ data.purchaseQty }}</div>
        </div>
        <div class="col">
          <div class="label">采购单价：</div>
          <div class="value">{{ data.price }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">合同金额：</div>
          <div class="value">{{ data.totalAmount }}</div>
        </div>
      </div>
    </div>
    <div class="content sub-content">
      <div class="info">
        <div class="title">审批流程</div>
        <div class="row">
          <div class="col">
            <Input v-model="remark" type="textarea" placeholder="请输入审批意见"/>
          </div>
        </div>
        <div class="row">
          <div class="col">
            <Button type="primary" :disabled="data.approveType !== 0" style="margin-right: 10px" @click="cfm(0)">同意</Button>
            <Button type="error" :disabled="data.approveType !== 0" style="margin-right: 10px" @click="cfm(1)">驳回</Button>
            <Button type="error" v-if="data.approveType === 1" @click="cfm(2)">撤回</Button>
          </div>
        </div>
        <div class="table">
          <table>
            <tr>
              <th>序号</th>
              <th>审批节点</th>
              <th>审批人</th>
              <th>审批意见</th>
              <th>审批结果</th>
              <th>审批日期</th>
            </tr>
            <tr v-for="(item, index) in flowsList" :key="index">
              <td>{{ item.rowNo }}</td>
              <td>{{ item.nodeName }}</td>
              <td>{{ item.userName }}</td>
              <td>{{ item.suggestions }}</td>
              <td>{{ item.checkResult }}</td>
              <td>{{ item.checkTime }}</td>
            </tr>
          </table>
        </div>
      </div>
    </div>
  </modal>
</template>

<script>
import { ApprovalBillFlow } from '@/api/applyPurchase'
import { GetApprovalFlows } from '@/api/stock'

export default {
  name: 'contract-form',
  data () {
    return {
      tabIndex: 0,
      formData: {},
      remark: '',
      modal: false,
      flowsList: [],
      infoData: {}
    }
  },
  components: {
  },
  props: {
    data: {
      type: Object,
      default () {
        return {}
      }
    },
    value: {
      type: Boolean,
      default: false,
      require: true
    }
  },
  watch: {
    value: {
      handler (n) {
        this.modal = n
      },
      immediate: true
    },
    modal (n) {
      this.$emit('input', n)
      if (n) {
        GetApprovalFlows({
          linkId: this.data.linkId
        }).then(res => {
          if (res.code === 0) {
            this.flowsList = res.result
          }
        })
      }
    }
  },
  methods: {
    cfm (type) {
      ApprovalBillFlow({
        linkCheckId: [this.data.flowChekId],
        updateAction: type,
        suggestions: this.remark
      }).then(res => {
        if (res.code === 0) {
          this.cancel()
          this.$Message.info(res.msg || '操作成功！')
          this.$emit('getlist')
        }
      })
    },
    cancel () {
      this.remark = ''
      this.modal = false
    }
  }
}
</script>

<style lang="less" scoped>
.content {
  padding: 10px 0;
  border-radius: 5px;
  background-color: #FFFFFF;
  &.sub-content {
    background-color: #f2f2f2;
    margin-top: 3px;
    .title {
      padding-top: 0;
    }
  }
  .title {
    text-align: center;
    font-size: 20px;
    font-weight: bold;
  }
  .sub-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px;
    font-size: 14px;
    font-weight: bold;
    &.border {
      border-bottom: 1px solid #000000;
    }
    .go {
      font-size: 10px;
      font-weight: normal;
      color: #0000ff;
    }
    .tabs {
      margin-bottom: 1px;
      display: flex;
      justify-content: space-between;
      border: 1px solid #5d6c7b;
      border-radius: 2px;
      font-size: 12px;
      font-weight: normal;
      .tab {
        width: 50px;
        text-align: center;
        border-right: 1px solid #5d6c7b;
        cursor: pointer;
        &:last-child {
          border-right: none;
        }
        &.active {
          background-color: rgba(22, 155, 213, 1);
          color: #FFFFFF;
        }
      }
    }
  }
  .row-wrap {
    position: relative;
    .pic {
      position: absolute;
      right: 20px;
      top: 50%;
      transform: translateY(-50%);
      width: 50px;
      img {
        width: 100%;
      }
    }
  }
  .row {
    padding: 0 20px;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .col {
      flex: 1;
      display: flex;
      align-items: flex-start;
      .value {
        flex: 1;
      }
    }
  }
  .card {
    margin-bottom: 5px;
    background-color: #FFFFFF;
    border: 1px solid rgba(215, 215, 215, 1);
    border-radius: 5px;
    .border {
      border-bottom: 1px solid #5d6c7b;
    }
    .line {
      width: 100%;
      border-bottom: 1px solid #5d6c7b;
    }
  }
  .table {
    padding: 0 20px;
    padding-bottom: 20px;
    table {
      border-collapse:collapse;
      border:none;
      width: 100%;
      tr {
        td,th {
          padding: 5px;
          text-align: center;
          border:solid #dcdee2 1px;
          position: relative;
          font-size: 12px;
        }
        th {
          background-color: #eeeeee;
        }
      }
    }
  }
}
/deep/ .ivu-modal-body {
  padding: 0;
  max-height: 80vh;
  overflow: auto;
}
/deep/ .ivu-modal-content {
  background-color: transparent;
}
</style>
