// 内转钢坯界面，留作备用
<template>
  <div class="inwardBilletRequirement">
    <div class="sache">
      <el-input placeholder="请输入内容" v-model="inputText" clearable>
      </el-input>
      <span>需求时间：</span>
      <el-date-picker
        v-model="startTime"
        type="datetime"
        placeholder="选择日期"
        style="width:220px"
      >
      </el-date-picker>
      <span>至</span>
      <el-date-picker
        v-model="endTime"
        type="datetime"
        placeholder="选择日期"
        style="width:220px"
      >
      </el-date-picker>
      <el-button type="primary" class="btn" @click="onclick">
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button type="primary" class="btn" @click="toInsert2">
        <i class="el-icon-plus"></i>新增
      </el-button>
    </div>
    <template>
      <div>
        <mergeRowTable v-bind.sync="first" ref="table">
          <el-table-column fixed="right" label="操作" width="80">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="mini"
                @click="closeRequirement(scope)"
              >
                停止
              </el-button>
              <el-button
                type="text"
                size="mini"
                @click="getRequirementOrder(scope)"
                >运单</el-button
              >
            </template>
          </el-table-column>
        </mergeRowTable>
      </div>
    </template>
  </div>
</template>
<script>
import { getCookie } from '@/utils/util.js'
import { sjTime } from '@/utils/sharedJsFile'
export default {
  data() {
    return {
      inputText: null,
      orgCode: '',
      startTime: null,
      endTime: null,
      first: {
        // first请求数据的地址
        requestUrl: ''
      }
    }
  },
  created() {
    if (
      getCookie('orgCode') == 'dagangadmin' ||
      getCookie('orgCode') == 'zidonghuabu'
    ) {
      this.first.requestUrl = '/api/v1/ams/getBilletRequirementList?apiId=518'
    } else {
      this.first.requestUrl =
        '/api/v1/ams/getBilletRequirementList?apiId=518&orgCode=' +
        getCookie('orgCode')
    }
  },
  mounted() {},
  methods: {
    onclick() {
      let orgCode = null
      let startTime = null
      let endTime = null
      if (this.startTime && this.endTime) {
        startTime = sjTime(this.startTime)
        endTime = sjTime(this.endTime)
      }
      if (
        getCookie('orgCode') != 'dagangadmin' &&
        getCookie('orgCode') != 'zidonghuabu'
      ) {
        orgCode = getCookie('orgCode')
      }
      this.first.requestUrl =
        '/api/v1/ams/getBilletRequirementList?apiId=518&requirementStatus=0&orgCode=' +
        orgCode +
        '&index=' +
        this.inputText +
        '&startTime=' +
        startTime +
        '&endTime=' +
        endTime +
        '&i=' +
        new Date()
    },
    //查看需求下面的运单
    getRequirementOrder(scope) {
      this.$router.push('/getRequirementOrder/' + scope.row.requirementId)
    },
    handleClick(tab, event) {
      this.getRequestUrl()
    },
    getRequestUrl() {
      if (
        getCookie('orgCode') == 'dagangadmin' ||
        getCookie('orgCode') == 'zidonghuabu'
      ) {
        this.first.requestUrl =
          '/api/v1/ams/getBilletRequirementList?apiId=518&requirementStatus=0&i=' +
          new Date()
      } else {
        this.first.requestUrl =
          '/api/v1/ams/getBilletRequirementList?apiId=518&requirementStatus=0&orgCode=' +
          getCookie('orgCode') +
          '&i=' +
          new Date()
      }
    },
    toInsert2() {
      this.$router.push('/addInwardBillet')
    },
    closeRequirement(scope) {
      this.$confirm('是否停止转运', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      })
        .then(() => {
          this.axios
            .post(
              '/api/v1/ams/closeDueDate?requirementId=' +
                scope.row.requirementId
            )
            .then(res => {
              if (res.data.code == 200) {
                this.$message({
                  type: 'success',
                  message: '停止成功!'
                })
                this.getRequestUrl()
              } else {
                this.$message({
                  message: '停止失败',
                  type: 'warning'
                })
              }
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '删除操作已取消!'
          })
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.inwardBilletRequirement {
  margin-top: 20px;
  margin-left: 20px;
  .sache {
    margin-top: 30px;
    padding-bottom: 10px;
    .el-input {
      width: 20%;
    }
  }
}
</style>
