<!-- 退款详情 -->
<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">
          <div class="label">照片：</div>
          <div
            class="value pic"
          >
            <p
              style="color: #0077ff;text-decoration: underline;cursor: pointer;padding: 3px 0;"
              @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="row">
        <div class="col">
          <div class="label">备注信息：</div>
          <div class="value">{{ data.backRemark }}</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.stockBackWay === 0? '合同扣款' : '供应商退款' }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">收款账户：</div>
          <div class="value">{{ data.bankData && data.bankData.bankAccoutName }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">开户行：</div>
          <div class="value">{{ data.bankData && data.bankData.openBank }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">账号：</div>
          <div class="value">{{ data.bankData && data.bankData.bankAccout }}</div>
        </div>
      </div>
      <div class="sub-title border">
        <span>收款信息</span>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">到账时间：</div>
          <div class="value">
            <DatePicker v-model="collectMoneyTime" type="date" size="small" placeholder="Select date"></DatePicker>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col" style="align-items: center">
          <div class="label">上传附件：</div>
          <div class="value" style="flex: 1">
            <Upload action="" ref="uploadFileFlag" :before-upload="beforeFile">
              <Button icon="ios-cloud-upload-outline">
                上传文件
              </Button>
            </Upload>
          </div>
        </div>
      </div>
      <div class="row" v-for="(item, index) in picList" :key="index">
        <div class="col">
          <span @click="openPic(item)" style="color: blue;cursor: pointer;text-decoration: underline">
            {{ item.split('/')[item.split('/').length - 1] }}
          </span>
          <Icon type="ios-close" size="24" style="padding: 0 20px;cursor: pointer" @click="del(index)" />
        </div>
      </div>
    </div>
  </modal>
</template>

<script>
import { openPic } from '@/libs/util'
import { GetApplySceneBackData, RefundsStockBack } from '@/api/stock'
import MySelectInput from '_c/my-select-input'
import { UploadBase64 } from '@/api/upload'
export default {
  name: 'contract-form',
  data () {
    return {
      collectMoneyTime: '',
      data: {},
      modal: false,
      returnTypeList: [],
      openPic,
      selectList: [],
      sourceExpressList: [],
      picList: []
    }
  },
  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()
      }
    }
  },
  methods: {
    del (index) {
      this.picList.splice(index, 1)
    },
    beforeFile (file) {
      const reader = new FileReader()
      reader.readAsDataURL(file)
      reader.onload = (event) => {
        UploadBase64({
          fileBase64: event.srcElement.result,
          fileName: file.name,
          floder: 'order'
        }).then(res => {
          if (res.code === 0) {
            this.picList.push(res.result)
          }
        })
      }
      return false
    },
    cfm () {
      if (!this.collectMoneyTime) {
        return this.$Message.error('请选择处理时间')
      }
      RefundsStockBack({
        id: this.id,
        collectMoneyTime: this.collectMoneyTime,
        waterImageUrls: this.picList.join(',')
      }).then(res => {
        if (res.code === 0) {
          this.cancel()
          this.$Message.info(res.msg || '操作成功！')
          this.$emit('getlist')
        }
      })
    },
    cancel () {
      this.modal = false
    },
    getlist () {
      GetApplySceneBackData({
        id: this.id,
        backMaterialProgress: this.backMaterialProgress
      }).then(async res => {
        if (res.code === 0) {
          this.data = res.result
        }
      })
    }
  }
}
</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>
