<!-- 合同审批单 -->
<template>
  <modal v-model="modal" :footer-hide="true" width="700px" class-name="vertical-center-modal">
    <!--  表单主要内容  -->
    <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.purchaseBillNo }}</div>
        </div>
        <div class="col">
          <div class="label">交货日期：</div>
          <div class="value">{{ $dayjs(data.deliverTime).format('YYYY-MM-DD') }}</div>
        </div>
        <div class="col">
          <div class="label">签约时间：</div>
          <div class="value">{{ $dayjs(data.signTime).format('YYYY-MM-DD') }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">合同账期：</div>
          <div class="value">{{ data.accountPeriod }}</div>
        </div>
      </div>
      <div class="sub-title border">
        <span>合同明细</span>
        <a class="go" href="#"  @click="showContract">合同预览</a>
        <modal-contract v-model="show" :data="data"></modal-contract>
      </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.spec }}</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 class="col"></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>
    <!--  决策辅助内容  -->
    <side-bar v-model="showSider">
      <div class="content" style="padding: 16px 10px;">
        <div class="title">决策辅助</div>
        <div v-if="isNewSu == 0" style="color:#fff;background-color: red;padding: 5px 0;text-align: center;">本次申购供应商为新供应商！</div>
        <div class="card">
          <div class="sub-title border">库存信息</div>
          <div class="row">
            <div class="col">
              <div class="label">现有库存：</div>
              <div class="value">{{ otherList.stockQty }}</div>
            </div>
            <div class="col">
              <div class="label">滞留数量：</div>
              <div class="value">{{ otherList.delayQty }}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">安全库存： </div>
              <div class="value">{{ otherList.safetyQty }}</div>
            </div>
          </div>
        </div>
        <div class="card">
          <div class="sub-title border">申购信息</div>
          <div class="row">
            <div class="col">
              <div class="label">申购单号：</div>
              <div class="value">
                <a href="#">{{ otherList.applyBillNo }}</a>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">申购日期：</div>
              <div class="value">{{ otherList.applyTime }}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">申购说明：</div>
              <div class="value">{{ otherList.applyAccount }}</div>
            </div>
          </div>
        </div>
        <div class="card">
          <div class="sub-title border">近30天出库数据</div>
          <div class="row">
            <div class="col">
              <div class="label">领料：</div>
              <div class="value">{{ otherList.takeQty }}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">退货：</div>
              <div class="value">{{ otherList.backQty }}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">报废：</div>
              <div class="value">{{ otherList.breakDownQty }}</div>
            </div>
          </div>
        </div>
        <div class="card">
          <div class="sub-title border">供应商记录</div>
          <div class="supplier-title">
            <span>{{supplierDetail.name}}</span>
            
            <img v-if="supplierDetail.certificate  && supplierDetail.businessLicense" src="@/assets/images/dun.png" alt="">
            <img v-if="supplierDetail.warningCount > 0" src="@/assets/images/gaojin.png" alt="">
            <div class="qipao-warp" v-if="supplierDetail.warningTypeCount > 0">
              <img src="@/assets/images/qipao.png" style="" alt="">
              <div class="num">{{supplierDetail.warningTypeCount}}</div>
            </div>
            
          </div>
          <div  class="row">
            <div class="col  border">
              <div class="label">联系电话：</div>
              <div class="value">{{supplierDetail.telephone}}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">累计采购：</div>
              <div class="value">{{ otherList.totalPurQtyStr }}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">最新单价：</div>
              <div class="value">{{ otherList.latestPrice }}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">累计退货：</div>
              <div class="value">{{ otherList.totalBackQty }}</div>
            </div>
            <div class="col">
              <div class="label">退货率：</div>
              <div class="value">{{ otherList.backQtyRate }}</div>
            </div>
          </div>
          <div class="row">
            <div class="line"></div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">历史最低单价：</div>
              <div class="value">{{ otherList.lowestPrice }}</div>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <div class="label">历史最高单价：</div>
              <div class="value">{{ otherList.highestPrice }}</div>
            </div>
          </div>
          <div class="row">
            <div class="line"></div>
          </div>
          <div class="row">
            <line-chart style="height: 200px;width: 226px" :x-data="otherList.purPriceItemsX" :y-data="otherList.purPriceItemsY"></line-chart>
          </div>
        </div>
        <div class="card">
          <div class="sub-title border">其他供应商对比</div>
          <div v-for="(item, index) in otherList.otherSupplierItems" :key="index">
            <div class="row">
              <div class="col">
                <div class="label">供应商：</div>
                <div class="value">{{ item.supplierName }}</div>
              </div>
            </div>
            <div class="row">
              <div class="col">
                <div class="label">累计采购：</div>
                <div class="value">{{ item.totalPurQtyStr }}</div>
              </div>
            </div>
            <div class="row">
              <div class="col">
                <div class="label">最新单价：</div>
                <div class="value">{{ item.latestPrice }}</div>
              </div>
            </div>
            <div class="row">
              <div class="col">
                <div class="label">累计退货：</div>
                <div class="value">{{ item.totalBackQty }}</div>
              </div>
              <div class="col">
                <div class="label">退货率：</div>
                <div class="value">{{ item.backQtyRate }}</div>
              </div>
            </div>
            <div class="row" v-if="index !== (otherList.otherSupplierItems.length - 1)">
              <div class="line"></div>
            </div>
          </div>
          <div
            v-if="otherList.otherSupplierItems && otherList.otherSupplierItems.length === 0"
            style="text-align: center;margin-bottom: 10px;"
          >
            无其他供应商
          </div>
        </div>
        <div class="card" v-if="JSON.stringify(newPurData) != '{}'">
          <div class="sub-title border">面料上次采购信息</div>
          <div>
            <div class="row">
              <div class="col">
                <div class="label">{{newPurData.materialName }}</div>
              </div>
            </div>
            <div class="row">
              <div class="col">
                <div class="label">采购时间：</div>
                <div class="value">{{ newPurData.approvalTime }}</div>
              </div>
            </div>
            <div class="row">
              <div class="col">
                <div class="label">采购数量：</div>
                <div class="value">{{ newPurData.purchaseQty }}</div>
              </div>
            </div>
            <div class="row">
              <div class="col">
                <div class="label">供应商：</div>
                <div class="value">{{ newPurData.supplierName }}</div>
              </div>
            </div>
            <div class="row">
              <div class="col">
                <div class="label">合同号：</div>
                <div class="value">{{ newPurData.purchaseBillNo }}</div>
                <modal-contract v-model="show" :data="data"></modal-contract>
              </div>
            </div>
          </div>
        </div>
      </div>
    </side-bar>
  </modal>
</template>

<script>
import SideBar from '_c/my-modal-pay/my-modal-sidebar'
import LineChart from './line-chart'
import ModalContract from './modal-contract'
import { GetApprovalFlows } from '@/api/stock'
import { ApprovalBillFlow, GetPurContractPolicy } from '@/api/applyPurchase'
import axios from 'axios'
export default {
  name: 'contract-form',
  data () {
    return {
      otherList: [], // 决策辅助
      flowsList: [],
      show: false,
      formData: {},
      remark: '',
      modal: false,
      showSider: true,
      supplierDetail:{},
      isNewSu:1,
      newPurData:{},
    }
  },
  components: {
    SideBar,
    LineChart,
    ModalContract
  },
  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) {
        console.log()
        GetApprovalFlows({
          linkId: this.data.id
        }).then(res => {
          if (res.code === 0) {
            this.flowsList = res.result
          }
        })
        axios.get('/cloudApi/supplier/su/detail?id=' + this.data.supplierId, {}).then(res=>{
          if(res.data.code == 200){
            this.supplierDetail = res.data.data
          }
        })
        axios.get('/cloudApi/purchaseContract/check/isNewSu?materialCode=' + this.data.materialCode + '&supplierId=' + this.data.supplierId, {}).then(res=>{
          if(res.data.code == 200){
            this.isNewSu = res.data.data
          }
          
        })
        axios.get('/cloudApi/purchaseContract/last/newPur?materialCode=' + this.data.materialCode, {}).then(res=>{
          res.data.data.purchaseQty = (res.data.data.purchaseQty * 1).toFixed(2)
          this.newPurData = res.data.data
        })
        GetPurContractPolicy({
          id: this.data.id
        }).then(res => {
          if (res.code === 0) {
            this.otherList = res.result
          }
        })
      }
    }
  },
  methods: {
    // 合同预览
    showContract () {
      this.show = true
    },
    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>
.dn{
  display: none;
}
.supplier-title{
  overflow: hidden;
  
  .qipao-warp{
    position: relative;
    float: left;
    .num{
      position: absolute;
      top:2px;
      left: 10px;
      color: #fff;
      font-size: 12px;
      transform:scale(0.8)
    }
  }
  span{
    margin-left:12px;
    display: block;
    float: left;
    font-size: 14px;
    color: #1A3AF0;
  }
  img{
    width: 20px;
    display: block;
    margin-left: 5px;
    float: left;
  }
}
.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;
    }
  }
  .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>
