<template>
  <div id="">
    <a-layout>
      <a-layout-content style="border:1px solid #d5d5ff;margin-left:5px;padding:0px;overflow: auto;">
        <p style="font-weight:bolder;background-color:#d5d5ff;padding:3px;margin-bottom: 20px">信息填报</p>
        <a-form :model="formObj" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" :rules="rules">
          <p style="margin-top:10px;margin-bottom: 10px;overflow: hidden;">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">疏浚单位负责人情况</span>
            <span class="hrs"></span>
          </p>
          <a-form-item label="负责人姓名">
            <a-input v-model:value="formObj.depDuty" autocomplete="off" style="width:200px"></a-input>
          </a-form-item>
          <a-form-item label="负责人电话">
            <a-input v-model:value="formObj.depDutyPhone" autocomplete="off" style="width:200px"></a-input>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px;overflow: hidden;">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">砂石综合利用现场管理负责人情况</span>
            <span class="hrs"></span>
          </p>
          <a-form-item label="负责人姓名">
            <a-input v-model:value="formObj.siteDuty" autocomplete="off" style="width:200px"></a-input>
          </a-form-item>
          <a-form-item label="负责人电话">
            <a-input v-model:value="formObj.siteDutyPhone" autocomplete="off" style="width:200px"></a-input>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px;overflow: hidden;">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">监管责任人情况</span>
            <span class="hrs"></span>
          </p>
          <a-form-item label="监管责任人">
            <a-input v-model:value="formObj.depRegDuty" autocomplete="off" style="width:200px"></a-input>
          </a-form-item>
          <a-form-item label="监管责任人电话">
            <a-input v-model:value="formObj.depRegDutyPhone" autocomplete="off" style="width:200px"></a-input>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px;overflow: hidden;">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">监管单位情况</span>
            <span class="hrs"></span>
          </p>
          <a-form-item label="监管单位">
            <a-input v-model:value="formObj.depReg" autocomplete="off" style="width:200px"></a-input>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 8, offset: 16 }">
            <a-button type="primary" @click="addHandler" v-if="openType">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog && openType"
        :objType="52"
        :villType="52"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'疏浚沙石'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"></problem-dialog>
      <add-pic-com
        v-if="jqmmDialogShow"
        :dialogTitle="'相关材料'"
        :jqmmEngId="currentObjectRgstrId"
        :type="type"
        :openType="openType"
        @jqmmDialogClose="jqmmDialogClose"></add-pic-com>
    </a-layout>
  </div>
</template>

<script>
import { getRgstridDinasDuty } from '../../../api/duChaTianBao';
import request from '../../../utils/gw_ajax_request';
import { formatDateTimeD } from '../../../utils/gw_date.js';
import inputWith from '../../../widgets/inuptWith.vue';
import problemDialog from '../../duChaWenTi/problemDialog.vue';
import addPicCom from './addPic.vue';
export default {
  components: {
    inputWith: inputWith,
    problemDialog,
    addPicCom,
  },
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'openType',
  ],
  data() {
    var checkTel = (rule, value, callback) => {
      var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/; // 座机
      var isMob = /^[1][3,4,5,7,8][0-9]{9}$/; // 座机格式
      if (value && !isMob.test(value) && !isPhone.test(value)) {
        callback(new Error('请输入合理电话'));
      } else if (value && (isMob.test(value) || isPhone.test(value))) {
        callback();
      }
      // setTimeout(() => {

      // }, 1000);
    };
    return {
      objtbStatu: {
        dutyState: '',
        rgstrId: '',
        id: '',
        state: '',
      },
      rules: {
        wiunWaoLegPersTel: [{ validator: checkTel, trigger: 'blur' }],
        techPersTel: [{ validator: checkTel, trigger: 'blur' }],
        patrolPersTel: [{ validator: checkTel, trigger: 'blur' }],
      },
      jqmmDialogShow: false,
      type: '',
      formObj: {
        depDuty: '',
        depDutyPhone: '',
        siteDuty: '',
        siteDutyPhone: '',
        depRegDuty: '',
        depRegDutyPhone: '',
        depReg: '',
      },
      dialogFormVisible: false,
      formLabelWidth: '180px',
      loading: true,
      operationType1: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getRgstridObj();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getRgstridObj();
    },
  },
  methods: {
    jqmmDialogClose() {
      this.jqmmDialogShow = false;
    },
    showPic(type) {
      this.type = type;
      this.jqmmDialogShow = true;
    },
    getRgstridObj() {
      getRgstridDinasDuty(this.currentObjectRgstrId).then((res) => {
        //  res.data.dutyId去掉dutyId解决dutyId为空时不显示三个责任人
        if (res.data && Object.keys(res.data).length) {
          this.formObj = res.data;
          this.operationType1 = 'update';
        } else {
          this.formObj = {};
          this.operationType1 = 'add';
        }
      });
    },
    addHandler() {
      this.formObj['rgstrId'] = this.currentObjectRgstrId;
      this.formObj['recPersId'] = this.recPersId;
      console.log(this.formObj);
      this.objtbStatu.rgstrId = this.currentObjectRgstrId;
      this.objtbStatu.id = this.currentObjectRgstrId;
      if (
        this.formObj.depDuty != null &&
        this.formObj.depDuty != '' &&
        this.formObj.depDutyPhone != null &&
        this.formObj.depDutyPhone != '' &&
        this.formObj.siteDuty != null &&
        this.formObj.siteDuty != '' &&
        this.formObj.siteDutyPhone != null &&
        this.formObj.siteDutyPhone != '' &&
        this.formObj.depRegDuty != null &&
        this.formObj.depRegDuty != '' &&
        this.formObj.depRegDutyPhone != null &&
        this.formObj.depRegDutyPhone != '' &&
        this.formObj.depReg != null &&
        this.formObj.depReg != ''
      ) {
        this.objtbStatu.dutyState = '2';
        this.objtbStatu.state = '1';
        this.formObj['state'] = '2';
      } else if (
        (this.formObj.depDuty == null || this.formObj.depDuty == '') &&
        (this.formObj.depDutyPhone == null ||
          this.formObj.depDutyPhone == '') &&
        (this.formObj.siteDuty == null || this.formObj.siteDuty == '') &&
        (this.formObj.siteDutyPhone == null ||
          this.formObj.siteDutyPhone == '') &&
        (this.formObj.depRegDuty == null || this.formObj.depRegDuty == '') &&
        (this.formObj.depRegDutyPhone == null ||
          this.formObj.depRegDutyPhone == '') &&
        (this.formObj.depReg == null || this.formObj.depReg == '')
      ) {
        this.objtbStatu.dutyState = '0';
        this.formObj['state'] = '0';
      } else {
        this.objtbStatu.dutyState = '1';
        this.objtbStatu.state = '1';
        this.formObj['state'] = '1';
      }
      this.$confirm({
        title: '提示',
        content: '确认保存现场督察情况信息？',
        okType: 'warning',
        onOk: () => {
          if (this.operationType1 == 'add') {
            try {
              request
                .post('/bis/insp/dinas/duty/add', this.formObj)
                .then((res) => {
                  if (res.success) {
                    this.$message.success('添加成功');
                    request
                      .post('/bis/insp/dinas/update', this.objtbStatu)
                      .then((res) => {
                        res;
                      });
                    this.$emit('addShuiKuSuccess');
                  }
                });
            } catch (e) {}
          } else if (this.operationType1 == 'update') {
            try {
              request
                .post('/bis/insp/dinas/duty/update', this.formObj)
                .then((res) => {
                  if (res.success) {
                    this.$message.success('修改成功');
                    request
                      .post('/bis/insp/dinas/update', this.objtbStatu)
                      .then((res) => {
                        res;
                      });
                    this.$emit('addShuiKuSuccess');
                  }
                });
            } catch (e) {}
          }
        },
      });
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_DINAS_SCENC',
      };
      request
        .post('/bis/insp/item/ques/info/findItemByType', obj)
        .then((res) => {
          this.rsvrRules = res.data;
        });
    },
    addProblem(item) {
      const rest = this.rsvrRules.filter((e) => {
        return e.eName === item;
      });
      this.probId = rest[0].id;
      this.showAddProblemDialog = true;
    },
    formatRadio(val) {
      if (val == '1') {
        return '是';
      } else if (val == '2') {
        return '否';
      } else {
        return val;
      }
    },
    closePlDialog(val) {
      this.showAddProblemDialog = false;
    },
  },
};
</script>

<style lang='less' scoped>
#dcdxHeader {
  padding: 15px 20px;
}

#dxdcFooter {
  text-align: center;
}

#dxdcAside {
  border: 1px solid #d5d5ff;
}

.el-dialog__wrapper .el-treeWhite {
  /* max-height: 260px !important; */
}

.add-problem-icon {
  font-size: 16px;
}

.el-icon-camera-solid,
.el-icon-circle-plus {
  margin-left: 20px;
  color: #00bbff;
  font-size: 18px;
  line-height: 12px;
  vertical-align: middle;
  cursor: pointer;
}

.el-icon-circle-plus {
  vertical-align: top;
}

.tip_info {
  margin-left: 20px;
  font-size: 12px;
  color: #ff0000;
}
</style>
