<!-- 盘盈亏申请单 -->
<template>
  <modal v-model="modal" :footer-hide="true" width="700px">
    <!--  表单主要内容  -->
    <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.departmentName }}</div>
        </div>
        <div class="col">
          <div class="label">申请人：</div>
          <div class="value">{{ infoData.applyUserName }}</div>
        </div>
        <div class="col">
          <div class="label">申请时间：</div>
          <div class="value">{{ infoData.applyTime }}</div>
        </div>
      </div>
      <div class="sub-title border">
        <span>物料信息</span>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料编码：</div>
          <div class="value">{{ infoData.materialCode }}</div>
        </div>
        <div class="col">
          <div class="label">物料名称：</div>
          <div class="value">{{ infoData.materialName }}</div>
        </div>
        <div class="col"></div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">物料规格：</div>
          <div class="value">{{ infoData.spec }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">克重：</div>
          <div class="value">{{ infoData.unitWeight }}</div>
        </div>
        <div class="col">
          <div class="label">门幅：</div>
          <div class="value">{{ infoData.width }}</div>
        </div>
        <div class="col">
          <div class="label">单位：</div>
          <div class="value">{{ infoData.unitName }}</div>
        </div>
      </div>
      <div class="sub-title border">
        <span>修改信息</span>
      </div>
      <div class="row">
        <div
          class="table"
          style="width: 100%;padding: 0;height: 300px;max-height: 300px;overflow: hidden"
        >
          <my-table
            :data="list"
            :columns="columns"
            :is-show-filter="false"
            :is-show-page="false"
            :tooltip="false"
          >
          </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 MyTable from '_c/my-table/my-table'
import { ApprovalBillFlow } from '@/api/applyPurchase'
import { GetMaterialEditCheckData, GetTechnologyTypList } from '@/api/baseData'
import { GetApprovalFlows } from '@/api/stock'

export default {
  name: 'contract-form',
  data () {
    return {
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '属性字段',
          key: 'name',
          minWidth: 100
        },
        {
          title: '修改前',
          key: 'old',
          minWidth: 100
        },
        {
          title: '修改后',
          key: 'new',
          minWidth: 100
        }
      ],
      list: [],
      tabIndex: 0,
      formData: {},
      remark: '',
      modal: false,
      flowsList: [],
      infoData: {
        scanfErrorTagList: []
      },
      params: {
        pageIndex: 1,
        pageSize: 20,
        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
          }
        })
        this.list = []
        GetMaterialEditCheckData({
          id: this.data.linkId
        }).then(async res => {
          if (res.code === 0) {
            this.infoData = res.result
            let newData = ''
            let oldData = ''
            await this.getTechnologyTypList(
              this.infoData.newData.technologyType
            ).then(res => {
              newData = res
            })
            await this.getTechnologyTypList(
              this.infoData.oldData.technologyType
            ).then(res => {
              oldData = res
            })
            this.list.push({
              name: '抽检比例',
              new: this.infoData.newData.checkRate,
              old: this.infoData.oldData.checkRate,
              color:this.infoData.newData.checkRate != this.infoData.oldData.checkRate ? 'red' : null
            })
            this.list.push({
              name: '安全库存',
              new: this.infoData.newData.safetyStock,
              old: this.infoData.oldData.safetyStock,
              color:this.infoData.newData.safetyStock != this.infoData.oldData.safetyStock ? 'red' : null
            })
            this.list.push({
              name: '采购周期',
              new: this.infoData.newData.safetyWarnDay,
              old: this.infoData.oldData.safetyWarnDay,
              color:this.infoData.newData.safetyWarnDay != this.infoData.oldData.safetyWarnDay ? 'red' : null
            })
            this.list.push({ 
              name: '物料属性', 
              new: newData, 
              old: oldData
              })
            this.list.push({
              name: '物料类型',
              new: this.infoData.newData.categoryName,
              old: this.infoData.oldData.categoryName,
              color:this.infoData.newData.categoryName != this.infoData.oldData.categoryName ? 'red' : null
            })
            this.list.push({
              name: '备注',
              new: this.infoData.newData.remark,
              old: this.infoData.oldData.remark
            })
          }
        })
      }
    }
  },
  methods: {
    async getTechnologyTypList (code) {
      let text = ''
      await GetTechnologyTypList().then(res => {
        if (res.code === 0) {
          res.result.forEach(item => {
            if (item.value === code.toString()) {
              text = item.text
            }
          })
        }
      })
      return text
    },
    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>
.color-red{
  color: red;
}
.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;
    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;
}
/deep/ .ivu-modal-content {
  background-color: transparent;
}
</style>
