<template>
  <view class="addcontainer" style="margin: 20rpx;min-height: 300px; ">
    <view class="querybox" style=" margin-top: 10px; margin-left: 10px; margin-bottom: 20px;">
      <view class="querybox_title" style="display: flex; flex-direction: row;">
        <view style="color: #ca4341; margin-right:5px;">*</view>
        <view>项目编号：</view>
      </view>
      <view class="querybox_title"> {{projectName}}</view>
    </view>
    <view class="querybox" style="  margin-left: 10px; margin-bottom: 20px;">
      <view class="querybox_title" style="display: flex; text-align: right; flex-direction: row;">
        <view style="color: #ca4341; margin-right:5px;">*</view>
        <view style="width:80px;">要素：</view>
      </view>
      <view class="querybox_title" style="padding-right: 10px;"> {{name4}}</view>
    </view>

    <!--  <view class="listbox" style="width: 100%;">
      <uni-row style="width: 100%;" :gutter="0">
        <uni-col :xs="24" :sm="12" :md="12">
          <uni-card :is-shadow="true" style="padding:0">
            <template v-slot:title>
              <view style="line-height: 40px; text-align: center; background-color: rgb(241, 241, 241);
          color: rgb(0, 0, 0);">专业</view>
            </template>
            <uni-list class="unilistbox">
              <uni-list-item v-for="(item,index) in list1" :key="index" :showExtraIcon="true" :title="item.name"
                rightText="" style="border-bottom: 1px solid #eee;" :clickable='true' :showSwitch="false"
                @click="activelistitem(2,item,index)">
                <template v-slot:footer>
                  <u-icon name="checkbox-mark" v-if="item.active" color="#42b983" size="20px"></u-icon>
                </template>
              </uni-list-item>
            </uni-list>
          </uni-card>
        </uni-col>
        <uni-col :xs="24" :sm="12" :md="12">
          <uni-card :is-shadow="true" style="padding:0">
            <template v-slot:title>
              <view style="line-height: 40px; text-align: center; background-color: rgb(241, 241, 241);
         color: rgb(0, 0, 0);">单项</view>
            </template>
            <uni-list class="unilistbox">
              <uni-list-item v-for="(item,index) in list2" :key="index" :showExtraIcon="true" :title="item.name"
                rightText="" style="border-bottom: 1px solid #eee;" :clickable='true' :showSwitch="false"
                @click="activelistitem(3,item,index)">
                <template v-slot:footer>
                  <u-icon name="checkbox-mark" v-if="item.active" color="#42b983" size="20px"></u-icon>
                </template>
              </uni-list-item>
            </uni-list>
          </uni-card>
        </uni-col>
        <uni-col :xs="24" :sm="12" :md="12">
          <uni-card :is-shadow="true" style="padding:0">
            <template v-slot:title>
              <view style="line-height: 40px; text-align: center; background-color: rgb(241, 241, 241);
         color: rgb(0, 0, 0);">子项</view>
            </template>
            <uni-list class="unilistbox">
              <uni-list-item v-for="(item,index) in list3" :key="index" :showExtraIcon="true" :title="item.name"
                rightText="" style="border-bottom: 1px solid #eee;" :clickable='true' :showSwitch="false"
                @click="activelistitem(4,item,index)">
                <template v-slot:footer>
                  <u-icon name="checkbox-mark" v-if="item.active" color="#42b983" size="20px"></u-icon>
                </template>
              </uni-list-item>
            </uni-list>
          </uni-card>
        </uni-col>
        <uni-col :xs="24" :sm="12" :md="12">
          <uni-card :is-shadow="true" style="padding:0">
            <template v-slot:title>
              <view class="querybox_title" style="line-height: 40px; text-align: center; background-color: rgb(241, 241, 241);
        color: rgb(0, 0, 0);display: flex; flex-direction: row; justify-content: center;">
                <view style="color: #ca4341; margin-right:5px;">*</view>
                <view>要素</view>
              </view>


            </template>
            <uni-list class="unilistbox">
              <uni-list-item v-for="(item,index) in list4" :key="index" :showExtraIcon="true" :title="item.name"
                rightText="" style="border-bottom: 1px solid #eee;" :clickable='true' :showSwitch="false"
                @click="activelistitem(5,item,index)">
                <template v-slot:footer>
                  <u-icon name="checkbox-mark" v-if="item.active" color="#42b983" size="20px"></u-icon>
                </template>
              </uni-list-item>
            </uni-list>
          </uni-card>
        </uni-col>
      </uni-row>
    </view> -->

    <view class="qutiaojianbox" style="display: block; flex-direction: inherit;">

      <uni-row style="width: 100%;" :gutter="0">
        <uni-col :xs="24" :sm="12" :md="24">
          <view class="querybox" style="margin-bottom: 15px;">
            <view class="querybox_title" style="width:100px; text-align: right; ">建筑物：</view>
            <view @click="jzwpickerVisible = true; hideKeyboard()">
              <u-input v-model="formdata.buildingname" disabled disabledColor="#ffffff" clearable placeholder="请选择建筑物"
                @clear="jzwclear"></u-input>
            </view>

          </view>
        </uni-col>
        <uni-col :xs="24" :sm="12" :md="24">
          <view class="querybox">
            <view class="querybox_title" style="width:100px;text-align: right;">抽查部位：</view>
            <u-input style="width: 300px;" placeholder="请输入抽查部位" border="surround" clearable
              v-model="formdata.checkPoint"></u-input>
          </view>
        </uni-col>
        <uni-col :xs="24" :sm="12" :md="20">
          <view class="querybox" style="margin: 15px 0 15px 0;">
            <view class="querybox_title" style="width:90px;text-align: right;display: flex; flex-direction: row;">
              <view style="color: #ca4341; ">*</view>
              <view>是否存在问题：</view>
            </view>
            <u-radio-group v-model="formdata.result" placement="row" activeColor="#007aff">
              <u-radio activeColor="green" :name="1" label="是" style="margin-left: 20px; margin-right: 10px;"></u-radio>
              <u-radio activeColor="green" :name="2" label="否" style="margin-right: 10px;"></u-radio>
              <u-radio activeColor="green" :name="3" label="不涉及" style="margin-right: 10px;"></u-radio>
            </u-radio-group>
          </view>
        </uni-col>
        <uni-col :xs="24" :sm="12" :md="20" v-if="formdata.result=='1'">
          <view class="querybox" style="margin: 15px 0 15px 0;">
            <view class="querybox_title" style="width:90px;text-align: right;display: flex; flex-direction: row;">
              <view style="color: #ca4341; ">*</view>
              <view>问题是否因规范更替引起：</view>
            </view>
            <u-radio-group v-model="formdata.issueStandardChanged" placement="row" activeColor="#007aff">
              <u-radio activeColor="green" :name="1" label="是" style="margin-left: 20px; margin-right: 10px;"></u-radio>
              <u-radio activeColor="green" :name="2" label="否" style="margin-right: 10px;"></u-radio>
              <!-- <u-radio activeColor="green" :name="3" label="不涉及" style="margin-right: 10px;"></u-radio> -->
            </u-radio-group>
          </view>
        </uni-col>
      </uni-row>


    </view>

    <view class="qutiaojianbox" style="margin-top: 10px;">
      <view class="querybox">
        <view class="querybox_title" style="width:100px; text-align: right; ">问题描述：</view>
        <u-textarea v-model="formdata.issue" style="width:300px;" placeholder="请输入问题描述"></u-textarea>
      </view>
    </view>
    <view class="qutiaojianbox" style="margin-top: 10px;">
      <view class="querybox" style="width: 100%;">
        <view class="querybox_title" style="width:100px; text-align: right; ">问题图片：</view>
        <!-- <view class="newAddImg" @click="paizhao">

          <uni-icons type="camera-filled" color="#ccc" size="35"></uni-icons>

        </view> -->
        <!--  <u-upload :sizeType="['compressed']" :fileList="imgfileList1" @afterRead="afterRead" @delete="deletePic"
          name="1" multiple :maxCount="10"></u-upload> -->
        <view>
          <!-- <cl-upload :listStyle="{
          columns: 2,
          columnGap: '20rpx',
          rowGap:'20rpx',
          padding:'10rpx',
          height:'300rpx',
 
          radius:'20rpx'
      }" fileType="image" fileName="img"
            :imageFormData="{sourceType: ['camera', 'album'], compress: true, quality: 50}" :headers="upHeaders"
            v-model="imgfileList1" :counts='30' class="paizhaolistbox" :action="upurl" @onSuccess="onupSuccess"
            :useBeforeDelete='true' @beforeDelete="beforeimgDelete"></cl-upload> -->

          <cl-upload fileType="image" fileName="img"
            :imageFormData="{sourceType: ['camera', 'album'], compress: true, quality: 50}" :headers="upHeaders"
            v-model="imgfileList1" :counts='30' class="paizhaolistbox" :action="upurl" @onSuccess="onupSuccess"
            :useBeforeDelete='true' @beforeDelete="beforeimgDelete" :listStyle="{
            		columns: 5,
            		columnGap: '20rpx',
            		rowGap: '20rpx',
            		padding: '10rpx',
            		height: '200rpx',
            		radius: '20rpx'
            	}">
            <template v-slot:addImg>
              <view class="newAddImg">
                <uni-icons type="camera-filled" color="#ccc" size="35"></uni-icons>
              </view>
            </template>
          </cl-upload>
        </view>
      </view>
    </view>

    <view style="display: flex; margin-bottom: 30px; flex-direction: row; justify-content: space-around;">
      <u-button type="error" :disabled="!formdata.checkTableId" text="删除" @click="sahnchu()"
        style="width: 20%; margin-top: 100rpx;"></u-button>
      <u-button type="primary" text="保存并关闭" @click="baocun()" style="width: 20%; margin-top: 100rpx;"></u-button>
      <u-button type="success" text="保存并添加" @click="baocunbtj()" style="width: 20%; margin-top: 100rpx;"></u-button>
    </view>

    <!-- 建筑物自定义选择器组件 -->
    <customPicker :visible="jzwpickerVisible" title="选择建筑物" :options="jzwpickerConfig.options"
      :displayKey="jzwpickerConfig.displayKey" :valueKey="jzwpickerConfig.valueKey" :multiple="jzwpickerConfig.multiple"
      :searchable="jzwpickerConfig.searchable" :value="jzwpickerConfig.value" @confirm="jzwhandleConfirm"
      @cancel="jzwhandleCancel" />
    <!--  <UniMenu /> -->
  </view>
</template>

<script>
  import {
    getsafety_hazardInfo,
    getxmdwdefaultconditionlist,
    getchecktablelist,
    getbuildinglist,
    addsafety_hazard,
    upsafety_hazard,
    getcheckTableIdinfo
  } from "@/apis/zhixing"
  import {
    getToken,
    setToken,
    removeToken
  } from '@/utils/auth'
  import UniMenu from '@/components/uni-menu/uni-menu.vue'
  import comboxMore from '@/components/wl-combox-more/combox-more.vue'
  import useUserStore from '@/store/user';
  import ClUpload from '@/components/cl-upload/components/cl-upload/cl-upload.vue'
  import CustomPicker from '@/components/custom-search-picker/index.vue';

  export default {
    components: {
      UniMenu,
      comboxMore,
      ClUpload,
      CustomPicker,
    },

    data() {
      return {
        // upurl: import.meta.env.VITE_APP_BASE_PRE + '/safety_hazard/table/img',
        //  httpurl: import.meta.env.VITE_APP_BASE_PRE,
        upurl: "",
        httpurl: '',
        userStore: useUserStore(),
        jzwpickerVisible: false,
        jzwpickerConfig: {
          title: '选择建筑物',
          options: [],
          displayKey: 'name',
          valueKey: 'buildingId',
          multiple: false,
          searchable: true,
          value: ''
        },
        upHeaders: {
          Bearerauth: 'Bearer ' + getToken()
        },
        imgfileList1: [],
        upimgfileList1: [],
        list1: [],
        list2: [],
        list3: [],
        list4: [],
        jzwlist: [{
          buildingId: 0,
          name: '建筑物1'
        }],
        formdata: {
          checkTableId: null, //	检查表主键
          standardCheckTableId: 0,
          checkPoint: "", //	抽查部位（查验点）
          buildingId: 0, //	建筑物主键
          buildingname: '', //建筑物名称
          result: 2, //	查验结果(0:未选择 1:符合 2:不符合 3:不涉及)
          issueStandardChanged: null, //问题是否因规范更替引起(0:未选择不涉及 1:是 2:否 3:不涉及)
          issue: "", //	问题描述
          imgUrl: "", //	图片逗号间隔
          projectId: 0, //	项目主键
          remark: "" //	备注
        },
        projectid: '',
        projectName: '',
        checkTableId: '',
        id1: '',
        id2: '',
        id3: '',
        id4: '',
        name4: '',
        isedit: false,
        queryParams: {
          // pageNum: 1,
          // pageSize: 10,
          projectId: null,
          reasonable: false,
        },

      }
    },
    computed: {
      nick() {
        // debugger
        // return  userStore.username
        const userStore = useUserStore();
        return userStore.name
      },
      imageSrc() {

        const userStore = useUserStore();
        return userStore.avatar
      },

      username() {
        // debugger
        // return  userStore.username
        const userStore = useUserStore();
        return userStore.username
      },
      avatar() {
        //debugger
        const userStore = useUserStore();
        return userStore.avatar
      },
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50
      }
    },

    props: {
      //随机数
      sjnum: {
        type: Number,
        default: 0,
      },
      objitem: {
        //传过来的详情
        type: Object,
        default: null,
      },
    },
    watch: {
      sjnum: {
        handler: function(newVal, oldVal) {
          // debugger

          const userStore = useUserStore();
          this.upurl = userStore.allurl + '/safety_hazard/table/img';
          if (this.objitem.projectid) {
            this.projectid = this.objitem.projectid;
            this.projectName = this.objitem.projectName;
          }
          //  debugger
          // this.isedit = this.objitem.isedit == '1' ? true : false;
          this.checkTableId = this.objitem.checkTableId || 'null';

          this.isedit = this.checkTableId == 'null' ? false : true;
          // if (this.objitem.checkTableId) {
          this.projectName = this.objitem.projectName;
          this.id1 = this.objitem.id1;
          this.id2 = this.objitem.id2;
          this.id3 = this.objitem.id3;
          this.id4 = this.objitem.id4;
          this.name4 = this.objitem.name4;
          this.getinfo(); //详情
          //  }

          userStore.setparentmenutitle('执行');
          //debugger
          if (!this.checkTableId) {
            //新增
            this.getlistinfo(1, '0'); //获取标准库检查列表
            this.getjzwlist(); //获取建筑物
            //userStore.setchildrenmenutitle('添加检查点');
          } else {
            // userStore.setchildrenmenutitle('编辑检查点');

          }

        },
        immediate: true,
        deep: true, //对象内部的属性监听，也叫深度监听
      },
      //       leidatushow: {
      //         handler: function(newVal, oldVal) {
      //           let vm = this;
      //           //debugger
      //           this.leidatushowval = newVal;
      //           // #ifdef APP-PLUS
      //           if (newVal) {
      //             this.firdstart(); //开始扫描
      //           }
      //           // #endif

      //           // #ifndef APP-PLUS
      //           if (newVal) {
      //             this.timerId = setTimeout(() => {
      //               // 这里写上你想要延时5秒后执行的代码
      //               vm.getsblist();
      //             }, 3000);
      //           }
      //           // #endif
      //         },
      //         immediate: true,
      //         deep: true, //对象内部的属性监听，也叫深度监听
      //       },
    },
    // // 监听页面返回
    // onBackPress() {
    //   //debugger
    //   uni.redirectTo({
    //     url: '/pages/index/index'
    //   });
    //   // 阻止界面返回默认操作， 这一步主要是为了防止界面出现异常，uniapp有对onBackPress的详细讲解
    //   return true;
    // },

    onShow() {
      // const userStore = useUserStore();
      // this.upurl = userStore.allurl + '/safety_hazard/table/img';
      // userStore.setparentmenutitle('执行');
      // if (!this.checkTableId) {
      //   //新增
      //   this.getlistinfo(1, '0'); //获取标准库检查列表
      //   this.getjzwlist(); //获取建筑物
      //   userStore.setchildrenmenutitle('添加检查点');
      // } else {
      //   userStore.setchildrenmenutitle('编辑检查点');

      // }


    },
    onLoad: function(options) {
      //	debugger

      // if (options.projectid) {
      //   this.projectid = options.projectid;
      //   this.projectName = options.projectName;
      // }
      // //  debugger
      // this.isedit = options.isedit == '1' ? true : false;
      // if (options.checkTableId) {
      //   this.checkTableId = options.checkTableId;
      //   this.projectName = options.projectName;
      //   this.id1 = options.id1;
      //   this.id2 = options.id2;
      //   this.id3 = options.id3;
      //   this.id4 = options.id4;
      //   this.getinfo(); //详情
      // }




    },
    methods: {
      paizhao() {
        let vm = this;
        uni.chooseImage({
          count: 1, //默认9
          //  sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
          crop: {
            quality: 30, // 压缩质量（0-100）
            width: '10%', // 缩放宽度
            height: '10%', // 缩放高度
          },
          sourceType: ['album', 'camera'], //从相册选择
          success: function(res) {
            // debugger
            let tempFiles = res.tempFilePaths[0];

            vm.uploadFilePromise(tempFiles)
            //console.log(JSON.stringify(res.tempFilePaths));
          }
        });
      },

      onupSuccess(reslut) {
        // debugger
        // 把服务端返回的图片地址添加到list中与组件数据同步
        if (reslut.code == 200) {
          // this.imgfileList1.push(this.httpurl + reslut.data);
          this.imgfileList1.push(this.userStore.allurl + reslut.data);
          this.upimgfileList1.push(reslut.data);
          //console.log("sdasd",this.imgfileList1);
        } else {

          this.$modal.msgError(`图片上传出错！` + reslut.msg)
        }
      },

      beforeimgDelete(item, index, next) {
        let _self = this;
        uni.showModal({
          title: '提示信息',
          content: '确定要删除这张图片嘛？',
          success: res => {
            if (res.confirm) {
              _self.imgfileList1.splice(index, 1);
              _self.upimgfileList1.splice(index, 1);

              // 模拟服务器接口
              // setTimeout(() => {
              //   next();
              // }, 1000);
            }
          }
        });
      },
      activelistitem(num, item, index) {
        // item.active = true;

        for (let x of this["list" + String(num - 1)]) {
          x.active = false;
        }
        this["list" + String(num - 1)][index].active = true;


        if (num != 5) {
          this.getlistinfo(num, item.standardCheckTableId)
        } else {
          this.formdata.standardCheckTableId = item.standardCheckTableId;

        }

      },

      getjzwlist() {
        //获取建筑物
        getbuildinglist({
          projectId: this.projectid
        }).then((res) => {
          //  debugger
          this.jzwlist = res.rows || [];
          this.jzwpickerConfig.options = res.rows || [];
          if (this.checkTableId) {
            //编辑
            let foundObject = this.jzwpickerConfig.options.find((obj) => obj.buildingId == this.formdata
              .buildingId);
            if (foundObject) {
              this.formdata.buildingname = foundObject.name;
            }


          }
          if (this.isedit) {
            // debugger
            // this.jzwpickerConfig.value = this.formdata.buildingId; 
            if (this.formdata.buildingId) {
              let xx = this.jzwlist.filter(item => item.buildingId == this.formdata.buildingId);
              if (xx.length > 0) {
                this.jzwpickerConfig.value = xx[0];
              }
            }

            // this.xmpickerConfig.value = this.xmdwlist.filter(item => res.data.areaIds.includes(item.value));
          }



        });
      },

      getlistinfo(index, parentId) {
        //获取检查列表
        // debugger
        getchecktablelist({
          parentId: parentId
        }).then((res) => {
          //debugger
          //if (!res.rows) return;
          res.rows = res.rows || [];
          for (let s of res.rows) {
            s.active = false;
          }
          // debugger

          if (index == 1) {
            if (this.checkTableId) {
              //编辑回显
              for (let s of res.rows) {
                if (s.standardCheckTableId == this.id1) {
                  s.active = true;
                }
              }
            }
            this.list1 = res.rows;
            if (this.list1.length == 0) {
              this.list2 = [];
              this.list3 = [];
              this.list4 = [];
              this.formdata.standardCheckTableId = 0;
            }

          } else if (index == 2) {
            //  debugger
            if (this.checkTableId) {
              //编辑回显
              for (let s of res.rows) {
                if (s.standardCheckTableId == this.id2) {
                  s.active = true;
                }
              }
            }
            this.list2 = res.rows;
            if (this.list2.length == 0) {
              this.list3 = [];
              this.list4 = [];
              this.formdata.standardCheckTableId = 0;
            }
          } else if (index == 3) {
            if (this.checkTableId) {
              //编辑回显
              for (let s of res.rows) {
                if (s.standardCheckTableId == this.id3) {
                  s.active = true;
                }
              }
            }
            this.list3 = res.rows;
            if (this.list3.length == 0) {

              this.list4 = [];
              this.formdata.standardCheckTableId = 0;
            }
          } else if (index == 4) {
            if (this.checkTableId) {
              //编辑回显
              for (let s of res.rows) {
                if (s.standardCheckTableId == this.id4) {
                  s.active = true;
                }
              }
            }
            this.list4 = res.rows;
          }


        })
      },


      // 新增图片
      async afterRead(event) {
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        let lists = [].concat(event.file)
        let fileListLen = this[`imgfileList${event.name}`].length
        lists.map((item) => {
          this[`imgfileList${event.name}`].push({
            ...item,
            status: 'uploading',
            message: '上传中'
          })
        })
        for (let i = 0; i < lists.length; i++) {
          const result = await this.uploadFilePromise(lists[i].url)
          let item = this[`fileList${event.name}`][fileListLen]
          this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
            status: 'success',
            message: '',
            url: result
          }))
          fileListLen++
        }
      },
      uploadFilePromise(url) {
        return new Promise((resolve, reject) => {
          // let httpurl = import.meta.env.VITE_APP_BASE_PRE;
          // let httpurl = "";
          // // #ifdef H5
          // httpurl = import.meta.env.VITE_APP_BASE_PRE
          // // #endif
          // // #ifndef H5
          // httpurl = userStore.allurl
          // // #endif
          let httpurl = this.userStore.allurl;
          let a = uni.uploadFile({
            url: httpurl + '/safety_hazard/table/img', // 仅为示例，非真实的接口地址
            filePath: url,
            name: 'img',
            header: {
              Bearerauth: 'Bearer ' + getToken()
            },
            // formData: {
            //   img: url
            // },
            success: (res) => {
              setTimeout(() => {
                resolve(res.data.data)
              }, 1000)
            }
          });
        })
      },

      ///*** 新的***/
      hideKeyboard() {
        uni.hideKeyboard()
      },
      jzwhandleConfirm(result) {
        // 处理确认建筑物
        //debugger
        // console.log(result);
        this.jzwpickerConfig.value = result.selectedItem;
        this.formdata.buildingname = result.selectedItem.name;
        this.formdata.buildingId = result.selectedItem.buildingId;
        this.jzwpickerVisible = false

      },
      jzwhandleCancel() {
        // 处理取消建筑物
        this.jzwpickerVisible = false
      },
      jzwclear() {
        //建筑物 
        this.formdata.buildingname = null;
        this.formdata.buildingId = null;
        this.jzwpickerConfig.value = '';
      },
      getinfo() {
        //获取详情
        //debugger
        if (this.checkTableId == "null") {
          this.getlistinfo(1, 0);
          this.getlistinfo(2, this.id1);
          this.getlistinfo(3, this.id2);
          this.getlistinfo(4, this.id3);
          this.formdata.standardCheckTableId = this.id4;
          this.getjzwlist(); //获取建筑物
          return;
        }
        //  debugger
        getcheckTableIdinfo(this.checkTableId).then((res) => {
          //debugger
          let httpurl = this.userStore.allurl;
          this.formdata = res.data;
          this.getlistinfo(1, 0);
          this.getlistinfo(2, this.id1);
          this.getlistinfo(3, this.id2);
          this.getlistinfo(4, this.id3);
          this.formdata.standardCheckTableId = this.id4;
          if (this.isedit) {
            //  this.jzwpickerConfig.value = this.formdata.buildingId;
            if (this.formdata.imgNum) {
              //图片
              if (this.formdata.imgUrl.includes(',')) {
                // debugger
                // this.imgurlslist = item.imgUrl.split(",");
                let imglist = this.formdata.imgUrl.split(",");
                for (let s of imglist) {

                  this.imgfileList1.push(httpurl + s);
                  this.upimgfileList1.push(s);
                }
                // this.imgurlslist = imglist;
              } else {

                this.imgfileList1 = [httpurl + this.formdata.imgUrl];
                this.upimgfileList1 = [this.formdata.imgUrl];
              }
            }

          } else {
            //新增时
            this.formdata.checkTableId = null;
            this.formdata.checkPoint = "";
            this.formdata.buildingId = "";
            this.formdata.buildingname = "";
            this.formdata.issueStandardChanged = null;
            this.formdata.result = '';
            this.formdata.issue = "";
            this.formdata.imgUrl = "";
            this.formdata.remark = "";
            this.imgfileList1 = [];
            this.upimgfileList1 = [];
          }

          this.getjzwlist(); //获取建筑物

        });

      },
      baocun() {
        //保存
        // formdata: {
        //   checkTableId: 0, //	检查表主键
        //   standardCheckTableId: 0,
        //   checkPoint: "", //	抽查部位（查验点）
        //   buildingId: 0, //	建筑物主键
        //   result: 0, //	查验结果(0:未选择 1:符合 2:不符合 3:不涉及)
        //   issue: "", //	问题描述
        //   imgUrl: "", //	图片逗号间隔
        //   projectId: 0, //	项目主键
        //   remark: "" //	备注
        // },

        if (!this.formdata.standardCheckTableId) {
          this.$modal.msgError("请选择要素！")
          return;
        }
        //  else if (!this.formdata.buildingId) {
        //   this.$modal.msgError("请选择建筑物！")
        //   return;
        // } 
        else if (!this.formdata.result) {
          this.$modal.msgError("请选择是否存在问题！")
          return;
        } else if (this.formdata.result == '1') {
          if (!this.formdata.issueStandardChanged) {
            this.$modal.msgError("请选择问题是否因规范更替引起！")
            return;
          }

        }
        this.formdata.imgUrl = this.upimgfileList1.toString();
        this.formdata.projectId = this.projectid;
        //debugger
        if (this.checkTableId != '' & this.isedit) {
          //编辑
          upsafety_hazard(this.formdata).then(res => {
            //debugger
            this.$modal.msgSuccess("修改成功！");
            // uni.navigateBack({
            //   delta: 1, // 默认返回上一页，数值越大返回层数越多
            //   success: () => {
            //     console.log('返回成功')
            //   }
            // });
            setTimeout(() => {
              this.$emit("righteventclose"); //执行父级函数
            }, 300);

          });
        } else {
          addsafety_hazard(this.formdata).then(res => {
            // debugger
            this.$modal.msgSuccess("添加成功！");
            // uni.navigateBack({
            //   delta: 1, // 默认返回上一页，数值越大返回层数越多
            //   success: () => {
            //     console.log('返回成功')
            //   }
            // });
            setTimeout(() => {
              this.$emit("righteventclose"); //执行父级函数
            }, 300);

          });
        }

      },

      baocunbtj() {
        //保存添加

        if (!this.formdata.standardCheckTableId) {
          this.$modal.msgError("请选择要素！")
          return;
        }
        //  else if (!this.formdata.buildingId) {
        //   this.$modal.msgError("请选择建筑物！")
        //   return;
        // } 
        else if (!this.formdata.result) {
          this.$modal.msgError("请选择是否存在问题！")
          return;
        } else if (this.formdata.result == '1') {
          if (!this.formdata.issueStandardChanged) {
            this.$modal.msgError("请选择问题是否因规范更替引起！")
            return;
          }

        }
        this.formdata.imgUrl = this.upimgfileList1.toString();
        this.formdata.projectId = this.projectid;

        if (this.checkTableId != '' & this.isedit) {
          //编辑
          upsafety_hazard(this.formdata).then(res => {
            //debugger
            this.$modal.msgSuccess("修改成功！");

            // uni.navigateBack({
            //   delta: 1, // 默认返回上一页，数值越大返回层数越多
            //   success: () => {
            //     console.log('返回成功')
            //   }
            // });
            this.formdata.checkTableId = null;
            this.formdata.checkPoint = "";
            this.formdata.buildingId = "";
            this.formdata.buildingname = "";
            this.formdata.issueStandardChanged = null;
            this.formdata.result = 2;
            this.formdata.issue = "";
            this.formdata.imgUrl = "";
            this.formdata.remark = "";
            this.imgfileList1 = [];
            this.upimgfileList1 = [];
            this.isedit = false;

            setTimeout(() => {
              this.$emit("shaunxian"); //执行父级函数\
            }, 300);
          });
        } else {
          addsafety_hazard(this.formdata).then(res => {
            // debugger
            this.$modal.msgSuccess("添加成功！");

            // uni.navigateBack({
            //   delta: 1, // 默认返回上一页，数值越大返回层数越多
            //   success: () => {
            //     console.log('返回成功')
            //   }
            // });
            this.formdata.checkTableId = null;
            this.formdata.checkPoint = "";
            this.formdata.buildingId = "";
            this.formdata.buildingname = "";
            this.formdata.issueStandardChanged = null;
            this.formdata.result = 2;
            this.formdata.issue = "";
            this.formdata.imgUrl = "";
            this.formdata.remark = "";
            this.imgfileList1 = [];
            this.upimgfileList1 = [];
            this.isedit = false;


            setTimeout(() => {
              this.$emit("shaunxian"); //执行父级函数\
            }, 300);
          });
        }




      },
      sahnchu() {
        //删除
        this.$emit("sahnchuevent", this.formdata.checkTableId); //执行父级函数

      }



    }
  }
</script>

<style lang="scss" scoped>
  .addcontainer {
    // width: 100%;
    display: flex;
    flex-direction: column;

    ::v-deep.u-form-item {
      font-size: 16px;
    }

    ::v-deep.u-form-item__body__left__content__required {
      line-height: 5px;
    }

    .listbox {
      display: flex;
      flex-direction: row;

      ::v-deep .unilistbox {
        max-height: 600rpx;
        height: 600rpx;
        overflow-y: auto;

        .uni-list--border-top {
          display: none;
        }

        .uni-list--border-bottom {
          display: none;
        }
      }

    }
  }

  .querybox {
    display: flex;
    flex-direction: row;
    align-items: center;

    .querybox_title {}
  }

  .qutiaojianbox {
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-left: 20px;

    .querybox {
      display: flex;
      flex-direction: row;
      align-items: center;
      margin-right: 60rpx;

      .querybox_title {
        width: 100px;
      }

      .imgbox {
        width: calc(100% - 100px);
      }
    }
  }

  .newAddImg {
    width: 80px;
    height: 80px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    border: 1px dashed #ccc;
    border-radius: 20rpx;
    color: #666;


  }
</style>