<!-- 盘点审核 -->
<template>
  <modal v-model="modal" :footer-hide="true" width="1000px">
    <!--  表单主要内容  -->
    <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">{{ infoData.checkUserName }}</div>
        </div>
        <div class="col">
          <div class="label">盘点部门：</div>
          <div class="value">仓库</div>
        </div>
        <div class="col">
          <div class="label">盘点时间：</div>
          <div class="value">{{ infoData.checkTime }}</div>
        </div>
      </div>
      <div class="sub-title border">
        <span>盘点明细</span>
      </div>
      <div class="row">
        <div class="table" style="width: 100%;padding: 0">
          <my-table :data="infoData.allStockCheckList" :columns="columns" :height="200" :isShowFilter="false" :is-show-page="false" :table-page="params" @on-change="changePage"></my-table>
        </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, GetFlowCheckDataPageList } from '@/api/stock'
import MyTable from '@/components/my-table/my-table'

export default {
  name: 'contract-form',
  data () {
    return {
      access: this.$store.state.user.access,
      tabIndex: 0,
      formData: {},
      remark: '',
      modal: false,
      flowsList: [],
      infoData: {},
      tableData: [],
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 40,
          align: 'center',
          fixed: 'left'
        },
        {
          title: '类型',
          key: 'technologyType',
          minWidth: 40,
          fixed: 'left'
        },
        {
          title: '用途',
          key: 'materialUse',
          minWidth: 60,
          fixed: 'left'
        },
        {
          title: '仓库名称',
          key: 'stockHouseName',
          minWidth: 80,
          fixed: 'left'
        },
        {
          title: '物料名称',
          key: 'materialName',
          minWidth: 150,
          fixed: 'left'
        },
        {
          title: '物料编码',
          key: 'materialCode',
          minWidth: 90,
          fixed: 'left'
        },
        {
          title: '库存数量',
          key: 'stockQty',
          minWidth: 80
        },
        {
          title: '盘点数量',
          key: 'checkStockQty',
          minWidth: 80
        },
        {
          title: '数量对比',
          key: 'qtyCompare',
          minWidth: 80
        },
        {
          title: '库存件数',
          key: 'tagCount',
          minWidth: 80
        },
        {
          title: '盘点件数',
          key: 'checkTagCount',
          minWidth: 80
        },
        {
          title: '件数对比',
          key: 'tagCountCompare',
          minWidth: 80
        },
        {
          title: '输入数量',
          key: 'everyDayHandQty',
          minWidth: 80
        },
        {
          title: '输入件数',
          key: 'everyDayHandTagQty',
          minWidth: 80
        },
        {
          title: '处置意见',
          key: 'dealRemark',
          minWidth: 150,
          align: 'center',
          fixed: 'right',
          render: (h, params) => {
            let that = this
            return h('Input', {
              props: {
                value: that.infoData.allStockCheckList[params.row._index].dealRemark,
                disabled: that.access === 'finance'
              },
              on: {
                'on-change' (val) {
                  that.infoData.allStockCheckList[params.row._index].dealRemark = val.target.value
                }
              }
            })
          }
        }
      ],
      params: {
        pageIndex: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  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
          }
        })
        GetFlowCheckDataPageList({
          id: this.data.linkId
        }).then(res => {
          this.infoData = res.result
          this.params.total = res.result.totalCount
        })
      }
    }
  },
  methods: {
    getObj (list) {
      let obj = {}
      list.forEach(item => {
        obj[item.detialId] = item.dealRemark
      })
      return obj
    },
    changePage (pageIndex) {
      this.params.pageIndex = pageIndex
      this.getList()
    },
    cfm (type) {
      ApprovalBillFlow({
        linkCheckId: [this.data.flowChekId],
        stockCheckDic: this.getObj(this.infoData.allStockCheckList),
        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.infoData = {}
      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;
}
/deep/ .ivu-table-cell {
  padding: 0 6px;
}
</style>
