<!-- 其他出库表单 -->
<template>
  <modal v-model="modal" :footer-hide="true" width="700px">
    <!--  表单主要内容  -->
    <div class="content">
      <div class="title">
        {{ type[data.stockOutType] }}
      </div>
      <div class="sub-title border">
        <span>申请信息</span>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">申请人：</div>
          <div class="value">{{ data.applyUserName }}</div>
        </div>
        <div class="col">
          <div class="label">申请时间：</div>
          <div class="value">{{ data.applyTime }}</div>
        </div>
      </div>
      <div class="sub-title border">
        <span>明细列表</span>
      </div>
      <div class="row" style="width: 100%;overflow: hidden">
        <my-table :data="data.materialItems" :columns="columns" :height="300" :is-show-filter="false" :is-show-page="false"></my-table>
      </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" v-if="access === 'purchase' && data.stockOutType === 0">
            <Button type="primary" :disabled="data.approveType !== 0" style="margin-right: 10px" @click="cfm(0)">提交</Button>
          </div>
          <div class="col" v-else>
            <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'
import MyTable from '_c/my-table/my-table'
import { openPic } from '@/libs/util'

export default {
  name: 'contract-form',
  data () {
    return {
      type: {
        0: '仓内退货',
        1: '仓内报损',
        2: '现场退货',
        3: '现场报废',
        4: '现场回仓'
      },
      access: this.$store.state.user.access,
      tabIndex: 0,
      formData: {},
      remark: '',
      modal: false,
      flowsList: [],
      infoData: {},
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '物料编码',
          key: 'materialCode',
          minWidth: 150
        },
        {
          title: '物料名称',
          key: 'materialName',
          minWidth: 150
        },
        {
          title: '供应商',
          key: 'supplierName',
          minWidth: 150
        },
        {
          title: '合同批次',
          key: 'batchNo',
          minWidth: 150
        },
        {
          title: '数量',
          key: 'takeQty',
          minWidth: 150
        },
        {
          title: '金额',
          key: 'amount',
          minWidth: 150
        },
        {
          title: '原因',
          key: 'applyReason',
          minWidth: 150
        },
        {
          title: '照片',
          key: 'imageUrls',
          minWidth: 200,
          render: (h, params) => {
            let arr = params.row.imageUrls.split(',')
            let els = []
            arr.forEach(item => {
              els.push(
                h('p', {
                  style: {
                    cursor: 'pointer',
                    color: 'blue',
                    padding: '3px 0',
                    textDecoration: 'underline'
                  },
                  on: {
                    click () {
                      openPic(item)
                    }
                  }
                }, item.split('/')[item.split('/').length - 1])
              )
            })
            return h('div', els)
          }
        }
      ]
    }
  },
  components: {
    MyTable
  },
  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>
