<template>
  <div>
      <el-dialog
        title="审核"
        :visible.sync="showToexamine"
        :before-close="handleClose"
        center
      >
      <el-form
          ref="toexamineForm"
          :rules="rules"
          :model="toexamineForm"
          label-width="100px"
        >
      <p class="title">系统信息</p>
        <el-row>
          <el-col :span="24">
            <el-form-item label="药店名称：">
              <el-input
                v-model="toexamineForm.pharmacyName"
                :disabled="notUser"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="所属地区：">
              <el-input
                v-model="areaVal"
                :disabled="notUser"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="详细地址：">
              <el-input
                v-model="toexamineForm.address"
                :disabled="notUser"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="经度：">
              <el-input
                v-model="toexamineForm.longitude"
                :disabled="notUser"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="纬度：">
              <el-input
                v-model="toexamineForm.latitude"
                :disabled="notUser"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <p class="title">调查信息</p>

        <el-row>
          <el-col :span="24">
            <el-form-item label="药店名称：">
              <el-input
                v-model="toexamineForm.temp3"
                :disabled="notUser"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">

            <el-form-item label="所属地区：">
              <el-input
                v-model="toexamineForm.temp7"
                :disabled="notUser"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="详细地址：">
              <el-input
                v-model="toexamineForm.temp4"
                :disabled="notUser"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="调查类型：">
              <el-select v-model="temp5Val" :disabled="notUser" class="temp5Sty">
                <el-option
                  v-for="item in temp5Data"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              <!-- <el-input
                v-model="toexamineForm.temp5"
                :disabled="notUser"
              ></el-input> -->
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="调查时间：">
              <el-input
                v-model="toexamineForm.temp6"
                :disabled="notUser"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="调研总结：">
              <el-input
                :disabled="notUser"
                :rows="4"
                type="textarea"
                autosize

                v-model="toexamineForm.temp9"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="调研情况：">
              <img :src="toexamineForm.temp8" alt="" class="imgStyle">
            </el-form-item>
          </el-col>
        </el-row>

         <p class="title">审批意见</p>
        <el-row>
          <el-col :span="24">
            <el-form-item label="审批意见：" prop="approvalopinion">
              <el-radio-group v-model="toexamineForm.approvalopinion">
                <el-radio label="1">采纳</el-radio>
                <el-radio label="2">拒绝</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="说明：">
              <el-input
                :rows="4"
                type="textarea"
                autosize
                placeholder="请输入内容"
                v-model="toexamineForm.approvalInfo"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        </el-form>

          <span slot="footer" class="dialog-footer" >
          <el-button @click="cancelBtn">取 消</el-button>
          <el-button type="primary" @click="sureBtn('toexamineForm')">确 定</el-button>
        </span>

      </el-dialog>
    </div>
</template>

<script>
  import { pharmacyApprova } from "@/api/wmtask";
  import maps from "qqmap"

  export default {
  name: "wmtask",

  data() {
    return {
      rules: {
        approvalopinion: [
          { required: true, message: "请选择审批意见", trigger: "change" },
        ],
      },
      showToexamine: true,
      toexamineForm: {
        pharmacyName: "",
        province: "",
        address: "",
        longitude: "",
        latitude: "",
        pharmacyName: "",
        temp3: "",
        temp4: "",
        temp7: "",
        temp8: "",
        temp5: "",
        temp6: "",
        temp9: "",
        approvalopinion: "",
        temp8: "",
        approvalInfo: ""
      },
      notUser: true,
      isCompareResult: true,
      pharmacyWmTask: {},
      idVal:{},
      showH5: true,
      taskSrc: "",
      temp5Data: [
        {
          value: "1",
          label: "药店柜台调查"
        },
        {
          value: "2",
          label: " 药店促销政策"
        }
      ],
      temp5Val: "",
      areaVal: "",
      current:'',
    }
  },

  mounted(){
    this.current = this.$route.query.current;
    let that = this;
    that.toexamineForm = that.$route.query.pharmacyInfo;
    that.pharmacyWmTask = that.$route.query.pharmacyWmTask;
    that.idVal = that.$route.query.arg;
    that.temp5Val = that.toexamineForm.temp5;

    // 所属地区展示省市区，拼接字符
    let provinceVal = that.toexamineForm.province == null ? "无" : that.toexamineForm.province;
    let cityVal = that.toexamineForm.city == null ? "无" : that.toexamineForm.city;
    let areaValue = that.toexamineForm.area == null ? "无" :  that.toexamineForm.area;

    this.areaVal = provinceVal +"-"+ cityVal +"-"+ areaValue;


    if(that.toexamineForm.compareResult == "1" || this.toexamineForm.compareResult== "3"){
      that.isCompareResult = false;
    } else{
      that.isCompareResult = true;
    }
  },
  methods:{
    sureBtn(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let args={
            taskId:this.idVal.taskId,
            approvalInfo:this.toexamineForm.approvalInfo,
            approvalOpinion:this.toexamineForm.approvalopinion,
            compareResult: this.toexamineForm.compareResult
          }
          pharmacyApprova(args).then(response => {

            if(response.data.code == "0"){
             this.$router.$avueRouter.closeTag();
              this.$message.success("审核完毕");
              this.$router.push({ path: '/admin/wmtask/auditCheck?current='+this.current});
              this.toexamineForm = {
                approvalopinion:"",
                approvalInfo: ""
              }

            }else{
              this.$message.error("请求异常");
                this.$router.push({ path: '/admin/wmtask/auditCheck?current='+this.current});
            }

          }).catch(() => {
            this.$message.error("请求异常");
          })

        } else {
          this.$message.error("请选择审批意见");
          return false;
        }
      });
    },
    // 取消按钮
    cancelBtn() {
      this.$router.$avueRouter.closeTag();
        this.$router.push({ path: '/admin/wmtask/auditCheck?current='+this.current});
      this.showToexamine = false;
      this.toexamineForm = {
        approvalopinion:"",
        approvalInfo: ""
      }
    },
    // esc取消
    handleClose(done) {
      done();
      this.$router.$avueRouter.closeTag();
      this.showToexamine = false;
        this.$router.push({ path: '/admin/wmtask/auditCheck?current='+this.current});
      this.toexamineForm = {
        approvalopinion:"",
        approvalInfo: ""
      }
    },
  }
  }
</script>

<style>
  .searchStyle{
    width: 100%;
    height:20px;
    font-weight:800;
    line-height:20px;
    border-bottom: 1px solid black;
    margin-bottom:20px;
  }
  .imgStyle{
    width:200px;
    height: 200px;
  }
  .temp5Sty{
    width: 230px;
  }
</style>


