//资源管理油价管理
<template>
  <!-- -->
  <div class="steel_inbound">
    <div class="sache">
      <el-input
        placeholder="请输入内容"
        v-model="textInput"
        clearable>
      </el-input>
      <el-button type="primary" class="btn1"  @click="onclick" :loading="selectLoading">
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button type="primary" class="btn" @click="toInsert">
        <i class="el-icon-plus"></i>新增
      </el-button>
    </div>
    <div class="table">
      <dilTable
        v-bind.sync="options"
        :isKuang="isKuang"
        @func="func"
        :loading="tableLoading"
      >
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="onEnable(scope)"
              v-if="scope.row.priceStatus !== '启用'"
            >
              启用
            </el-button>
            <el-button
              type="text"
              size="mini"
              @click="deleteOilPrice(scope)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </dilTable>
    </div>
  </div>
</template>
<script>
export default {
  name:"homeworkPath",
  data(){
    return{
      tableLoading:false,
      selectLoading:false,
      isKuang:false,
      //切换是否启用按钮和停用按钮
      enableStatus:true,
      textInput: "" ,
      restaurants: [],
      options:{
        // first请求数据的地址
        requestUrl: "/api/v1/rms/getOilPriceResultList?apiId=380",
      },
    }
  },
  methods:{
    func(res){
      if(this.selectLoading){
        this.selectLoading = false;
      }
      this.isKuang = false;
      this.tableLoading = false;
    },
    onclick(){
      this.isKuang = true;
      this.selectLoading = true;
      this.tableLoading = true;
      if(this.textInput!=null){
        this.textInput=this.textInput.replace('#','%23')
        this.textInput=this.textInput.replace('%','%25')
        this.options.requestUrl = "/api/v1/rms/getOilPriceResultList?apiId=380&con=" +this.textInput+"&i="+ new Date();
      }else{
        this.options.requestUrl = "/api/v1/rms/getOilPriceResultList?apiId=380&i="+ new Date();
      }
    },
    //跳转到新增页面
    toInsert() {
      this.$router.push("/addOilPrice");
    },
    deleteOilPrice(scope){
     this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.tableLoading = true;
        this.axios.post('/api/v1/rms/deleteOilPrice/'+scope.row.priceId).then((res)=>{
          if(res.data.code == "200"){
            this.$message.success('删除成功')
            this.options.requestUrl = "/api/v1/rms/getOilPriceResultList?apiId=380&i="+ new Date();
          }else{
            this.$message.error('删除失败，该油价正在启用!')
            this.options.requestUrl = "/api/v1/rms/getOilPriceResultList?apiId=380&i="+ new Date();
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除');
      });
    },
    onEnable(scope){
      this.$confirm('将要启用该油价, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios.post("/api/v1/rms/updateOilPrice",{"priceId":scope.row.priceId}).then((res) => {
          if (res.data.code == "200") {
            this.$message({ type: "success", message: "启用成功!",});
            this.options.requestUrl = "/api/v1/rms/getOilPriceResultList?apiId=380&i="+ new Date();
          }else{
            this.$message({ type: "error", message: "启用失败，请联系管理员!",});
          }

        });
      }).catch(() => {
        this.$message.info('已取消启用该油价!');
      });

    }
  },
}
</script>

<style lang="scss" scode>
.steel_inbound{
  .sache{
    width: 100%;height: 100px;
    display: flex;
    align-items: center;
    .el-input {
      width: 250px;
      margin-left: 50px;
      margin-right: 30px;
    }
    .btn1{
      margin-right: 30px;
    }
  }
  }
</style>
