<template>
  <div class="content-main">
    <el-form :inline="true" :model="detailForm" label-width="100px">
      <div v-show="$route.query.state != 'sum'">
        <el-row>
          <el-col :span="8" :offset="3">
            <el-form-item label="填报单位:">
              <el-input disabled v-model="detailForm.tbdwbmmc" class="input-box"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="填报日期:">
              <el-input disabled v-model="detailForm.tbrq" class="input-box"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8" :offset="3">
            <el-form-item label="填报人:">
              <el-input disabled v-model="detailForm.tbrbmmc" class="input-box"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话:">
              <el-input
               placeholder="请输入数字"
            type="number"
                :disabled="$route.query.state == 'detail'"
                v-model="detailForm.lxdh"
                class="input-box"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <div v-show="$route.query.state == 'sum'">
        <el-form-item label="年度:" label-width="270px">
          <el-input disabled v-model="detailForm.nd" class="input-box"></el-input>
        </el-form-item>
      </div>
      <el-row style="background: rgb(237, 245, 253); line-height: 50px;margin-bottom: 10px;">
        <span style="margin-left:10px">市场类型</span>
      </el-row>
      <el-row>
        <el-col :span="8" :offset="3">
          <el-form-item label="商流:">
            <el-input
             placeholder="请输入数字"
            type="number"
              :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
              v-model="detailForm.sl"
              class="input-box"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="成品粮:">
            <el-input
             placeholder="请输入数字"
            type="number"
              :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
              v-model="detailForm.cpl"
              class="input-box"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8" :offset="3">
          <el-form-item label="专业粮油:">
            <el-input
             placeholder="请输入数字"
            type="number"
              :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
              v-model="detailForm.zyly"
              class="input-box"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="综合性:">
            <el-input
             placeholder="请输入数字"
            type="number"
              :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
              v-model="detailForm.zhx"
              class="input-box"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row style="background: rgb(237, 245, 253); line-height: 50px;margin-bottom: 10px;">
        <span style="margin-left:10px">市场性质</span>
      </el-row>
      <el-row>
        <el-col :span="8" :offset="3">
          <el-form-item label="国有独资:">
            <el-input
             placeholder="请输入数字"
            type="number"
              :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
              v-model="detailForm.gydz"
              class="input-box"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="股份制:">
            <el-input
             placeholder="请输入数字"
            type="number"
              :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
              v-model="detailForm.gfz"
              class="input-box"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8" :offset="3">
          <el-form-item label="民营:">
            <el-input
              placeholder="请输入数字"
              type="number"
              :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
              v-model="detailForm.my"
              class="input-box"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row style="background: rgb(237, 245, 253); line-height: 50px;margin-bottom: 10px;">
        <span style="margin-left:10px">本年度市场交易情况</span>
      </el-row>
      <el-row>
        <el-col :span="8" :offset="3">
          <el-form-item label="成交量(万吨):" label-width="106px">
            <!-- <input  
            type="number"
              :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
              v-model="detailForm.cjl"
              class="input-box"
            placeholder="请输入纯数字"
            > -->
            <el-input 
              placeholder="请输入数字"
              type="number"
              :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
              v-model="detailForm.cjl"
              class="input-box"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="成交额(亿元):" label-width="120px">
            <el-input
              placeholder="请输入数字"
              type="number"
              :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
              v-model="detailForm.cje"
              class="input-box"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-form-item label="截至本年度本省(区、市)市场总数：" label-width="270px">
          <el-input
            placeholder="请输入数字"
            type="number"
            :disabled="$route.query.state == 'detail'||$route.query.state == 'sum'"
            v-model="detailForm.sczs"
            class="input-box"
          ></el-input>
        </el-form-item>
      </el-row>
    </el-form>

    <div style="text-align: center;margin-top:10px;">
      <el-button
        type="primary"
        @click="save"
        size="small"
        class="iconfont iconbaocun"
        v-show="$route.query.state !== 'detail' && $route.query.state !== 'sum'"
      >保存</el-button>
      <el-button type="primary" @click="retrunList" size="small" class="iconfont iconfanhui">返回</el-button>
      
      <!-- @click="scalePlanCancel" -->
    </div>
  </div>
</template>

<script>
import {
  insertEntitySelective,
  grainselectById,
  updateByEntitySelective
} from "@/api/grainCirculationPrice/foodMarketConstruction";
import { getNowDate } from "@/utils/index";
export default {
  data() {
    return {
      detailForm: {}
    };
  },
  created() {
    console.log(this.$route.query,'路由')
    if (this.$route.query.state) {
      if (this.$route.query.state == "sum") {
        this.detailForm = JSON.parse(this.$route.query.id);
      } else {
        this.getInfo();
      }
    } else {
      this.detailForm.tbdwlx =
        sessionStorage.getItem("orgCode").length == 5
          ? 0
          : sessionStorage.getItem("orgCode").length == 8
          ? 1
          : 2;
      this.detailForm.tbdwbmmc = sessionStorage.getItem("orgName");
      this.detailForm.tbdwbm = sessionStorage.getItem("orgCode");
      this.detailForm.tbrbmmc = sessionStorage.getItem("userName");
      this.detailForm.tbrq = getNowDate();
    }
  },
  methods: {
    retrunList() {
      this.$router.push({
        path: "index",
        query: {status:this.$route.query.msStatus}
      });
    },
    getInfo() {
      grainselectById({ jsbm: this.$route.query.id }).then(res => {
        if (res.infoCode == 200) {
          this.detailForm = res.data;
        } else {
          this.$message({
            message: res.msg,
            type: "error"
          });
        }
      });
    },
    save() {
      if (this.$route.query.state) {
        this.detailForm.ztbm = "0";
        this.detailForm.ztbmmc = "未上报";
        updateByEntitySelective(this.detailForm).then(res => {
          if (res.infoCode == 200) {
            this.$message({
              message: "保存成功",
              type: "success"
            });
            this.$router.push({path: "index",query: {status:this.$route.query.msStatus}});
          } else {
            this.$message({
              message: res.msg,
              type: "error"
            });
          }
        });
      } else {
        this.detailForm.ztbm = "0";
        this.detailForm.ztbmmc = "未上报";
        insertEntitySelective(this.detailForm).then(res => {
          if (res.infoCode == 200) {
            this.$message({
              message: "保存成功",
              type: "success"
            });
            this.$router.push({ path: "index", query: {status:this.$route.query.msStatus} });
          } else {
            this.$message({
              message: res.msg,
              type: "error"
            });
          }
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.input-box {
  width: 220px;
}
</style>
