<!-- 总经理审批 退料审批弹框 -->
<template>
  <modal v-model="modal" width="500px">
    <!--  表单主要内容  -->
    <div class="title" slot="header">报废处理</div>
    <div class="footer" slot="footer">
      <Button class="btn" type="primary" size="small" @click="cfm()">提交</Button>
    </div>
    <div class="content">
      <div class="sub-title border">
        <span>物料信息</span>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料名称：</div>
          <div class="value">{{ data.materialName }}</div>
        </div>
        <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.supplierName }}</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.purchaseBillNo }}</div>
        </div>
        <div class="col">
          <div class="label">采购日期：</div>
          <div class="value">{{ data.purchaseDate }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">采购单价：</div>
          <div class="value">{{ data.price }}</div>
        </div>
        <div class="col">
          <div class="label">采购数量：</div>
          <div class="value">{{ data.purchaseQty }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">选择入库批号：</div>
          <div class="value">{{ data.batchNo }}</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.backTime }}</div>
        </div>
        <div class="col">
          <div class="label">退料人员：</div>
          <div class="value">{{ data.backUserName }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">退料原因：</div>
          <div class="value">{{ data.backReason }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col" style="align-items: flex-start">
          <div class="label">照片：</div>
          <div
            class="value pic"
          >
            <p
              style="color: #0077ff;text-decoration: underline;cursor: pointer;margin-bottom: 3px;"
              @click="openPic(pic)" v-for="(pic, picIndex) in (data.imageUrls && data.imageUrls.split(','))" :key="picIndex">
              {{ pic.split('/')[pic.split('/').length - 1] }}
            </p>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">退料数量：</div>
          <div class="value">{{ data.backQty }}</div>
        </div>
        <div class="col">
          <div class="label">退料金额：</div>
          <div class="value">{{ data.backAmount }}</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.stockOutType }}</div>
        </div>
        <div class="col">
          <div class="label">退料人员：</div>
          <div class="value">{{ data.checkUserName }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">判定时间：</div>
          <div class="value">{{ data.checkTime }}</div>
        </div>
      </div>
      <div class="sub-title border">
        <span>报废处理</span>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">报废方式：</div>
          <div class="value">
            <my-select-input v-model="destroyWay" :list="selectList" size="small"></my-select-input>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">处理时间：</div>
          <div class="value">
            <DatePicker v-model="destroyTime" type="date" size="small" placeholder="Select date"></DatePicker>
          </div>
        </div>
      </div>
    </div>
  </modal>
</template>

<script>
import { openPic } from '@/libs/util'
import { GetApplySceneBackData, DestroyStockBack } from '@/api/stock'
import MySelectInput from '_c/my-select-input'
import { AddDataDictionary, DataDictionary } from '@/api/baseData'
export default {
  name: 'contract-form',
  data () {
    return {
      destroyWay: '',
      destroyTime: '',
      data: {},
      modal: false,
      returnTypeList: [],
      openPic,
      selectList: [],
      sourceExpressList: []
    }
  },
  components: {
    MySelectInput
  },
  props: {
    backMaterialProgress: {},
    id: {},
    value: {
      type: Boolean,
      default: false,
      require: true
    }
  },
  watch: {
    value: {
      handler (n) {
        this.modal = n
      },
      immediate: true
    },
    modal (n) {
      this.$emit('input', n)
      if (n) {
        this.getlist()
        this.getSelectList()
      }
    }
  },
  methods: {
    cfm () {
      if (!this.destroyWay) {
        return this.$Message.error('请选择报废方式')
      }
      if (!this.destroyTime) {
        return this.$Message.error('请选择处理时间')
      }
      DestroyStockBack({
        id: this.id,
        destroyTime: this.destroyTime,
        destroyWay: this.destroyWay
      }).then(res => {
        if (res.code === 0) {
          if (!this.sourceExpressList.find(item => item.key === this.destroyWay)) {
            this.cancel()
            this.$Message.info(res.msg || '操作成功！')
            this.$emit('getlist')
            AddDataDictionary({
              key: this.destroyWay,
              value: this.destroyWay,
              remark: '退料管理自动生成',
              groupCode: 4
            })
          }
        }
      })
    },
    cancel () {
      this.modal = false
    },
    getlist () {
      GetApplySceneBackData({
        id: this.id,
        backMaterialProgress: this.backMaterialProgress
      }).then(async res => {
        if (res.code === 0) {
          this.data = res.result
        }
      })
    },
    getSelectList () {
      DataDictionary({
        pageIndex: 1,
        pageSize: 99999,
        groupCode: 4
      }).then(res => {
        if (res.code === 0) {
          this.selectList = [ ...res.result.list ]
          this.sourceExpressList = [ ...res.result.list ]
        }
      })
    }
  }
}
</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: center;
      .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;
    max-height: 200px;
    overflow: auto;
    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;
}
</style>
