riku
2023-11-29 9b09d13712c0c005891450a3bf4b6d848ec0ff37
pages/mPromise/promiseinfo/promiseinfo.js
@@ -1,83 +1,72 @@
// pages/promiseinfo/promiseinfo.js
const userservice = require("../../../service/userservice")
const app = getApp()
import { getSceneName1 } from '../../../data/sceneTypes';
const userservice = require('../../../service/userservice');
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    sceneTypeMap: {
      '1': '餐饮',
      '2': '工地',
      '3': '码头',
      '4': '堆场',
      '5': '搅拌站',
      '6': '工业企业',
      '7': '汽修',
    },
    sceneType: '--',
    msg: [{
        name: "单位名称",
        id: "department",
        input: true,
        value: "",
        noValue: false
      },
    msg: [
      {
        name: "信用代码",
        id: "socialCode",
        input: true,
        value: "",
        noValue: false
      },
      {
        name: "报建号",
        id: "number",
        input: true,
        value: "",
        noValue: false,
        required: false
      },
      {
        name: "法人姓名",
        id: "juridicalPerson",
        name: '单位名称',
        id: 'department',
        input: true,
        value: '',
        noValue: false
        noValue: false,
      },
      {
        name: "身份证号",
        id: "idNo",
        name: '信用代码',
        id: 'socialCode',
        input: true,
        value: "",
        value: '',
        noValue: false,
        maxLength: 18
      },
      {
        name: '报建号',
        id: 'number',
        input: true,
        value: '',
        noValue: false,
        required: false,
      },
      {
        name: '法人姓名',
        id: 'juridicalPerson',
        input: true,
        value: '',
        noValue: false,
      },
      {
        name: '身份证号',
        id: 'idNo',
        input: true,
        value: '',
        noValue: false,
        maxLength: 18,
      },
    ],
    commitTypes: [{
    commitTypes: [
      {
        value: 'type1',
        name: '环保主体责任承诺',
        checked: true
        checked: true,
      },
      {
        value: 'type2',
        name: '环境行政许可事项',
        checked: false
        checked: false,
      },
      {
        value: 'type3',
        name: '环保专项资金或其他资金补助',
        checked: false
        checked: false,
      },
      {
        value: 'type4',
        name: '其他环保申报事项',
        checked: false
      }
        checked: false,
      },
    ],
    commitTypeIndex: 0,
  },
@@ -86,7 +75,7 @@
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let st = app.globalData.userInfo.extension2
    let st = app.globalData.userInfo.extension2;
    switch (st) {
      case '2':
      case '3':
@@ -94,106 +83,106 @@
      case '5':
      case '6':
        this.setData({
          'msg[2].name': '报建号'
        })
          'msg[2].name': '报建号',
        });
        break;
      case '1':
        this.setData({
          'msg[2].name': '环评审批文号',
          'msg[2].show': false,
        })
        });
        break;
      case '7':
        this.setData({
          'msg[2].name': '环评审批文号'
        })
          'msg[2].name': '环评审批文号',
        });
        break;
      default:
        this.setData({
          'msg[2].name': '环评审批文号'
        })
          'msg[2].name': '环评审批文号',
        });
        break;
    }
    this.setData({
      sceneType: this.data.sceneTypeMap[st]
    })
    this.getUserBaseInfo()
      sceneType: getSceneName1(st),
    });
    this.getUserBaseInfo();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },
  onReady: function () {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },
  onShow: function () {},
  changeMsg(e) {
    let id = e.detail.params.id
    let value = e.detail.params.value
    let msg = this.data.msg
    let msgLength = msg.length
    let id = e.detail.params.id;
    let value = e.detail.params.value;
    let msg = this.data.msg;
    let msgLength = msg.length;
    for (let i = 0; i < msgLength; i++) {
      if (msg[i].id === id) {
        let path = "msg[" + i + "].value"
        let nPath = "msg[" + i + "].noValue"
        let path = 'msg[' + i + '].value';
        let nPath = 'msg[' + i + '].noValue';
        this.setData({
          [path]: value,
          [nPath]: false
        })
          [nPath]: false,
        });
      }
    }
  },
  checkboxChange(e) {
    console.log('checkbox发生change事件,携带value值为:', e.detail.value)
    console.log('checkbox发生change事件,携带value值为:', e.detail.value);
    const items = this.data.commitTypes
    const values = e.detail.value
    const items = this.data.commitTypes;
    const values = e.detail.value;
    for (let i = 0, lenI = items.length; i < lenI; ++i) {
      items[i].checked = false
      items[i].checked = false;
      for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
        if (items[i].value === values[j]) {
          items[i].checked = true
          break
          items[i].checked = true;
          break;
        }
      }
    }
    this.setData({
      commitTypes: items
    })
      commitTypes: items,
    });
    // console.log(this.data.commitTypes);
  },
  getUserBaseInfo() {
    var that = this
    userservice.getBaseInfo(app.globalData.accessToken.userId, {
      success(data) {
        const msg = that.data.msg
        if (data.company) {
          msg[0].value = data.company.ciName
          msg[1].value = data.company.ciOrgCode
          msg[3].value = data.company.ciJuridicalPerson
        }
        that.setData({
          msg
        })
      }
    }, app.globalData.accessToken.openId)
    var that = this;
    userservice.getBaseInfo(
      app.globalData.accessToken.userId,
      {
        success(data) {
          const msg = that.data.msg;
          if (data.company) {
            msg[0].value = data.company.ciName;
            msg[1].value = data.company.ciOrgCode;
            msg[3].value = data.company.ciJuridicalPerson;
          }
          that.setData({
            msg,
          });
        },
      },
      app.globalData.accessToken.openId,
    );
  },
  onSubmit: function () {
    if (!this.submitCheck()) return
    if (!this.submitCheck()) return;
    var _data = this.data
    var _data = this.data;
    wx.navigateTo({
      url: '/pages/mPromise/promisefile/promisefile',
      success: function (res) {
@@ -212,65 +201,65 @@
          type4: _data.commitTypes[3].checked,
          year: '',
          month: '',
          day: ''
        })
      }
    })
          day: '',
        });
      },
    });
  },
  /**
   * 信息完整度检查
   */
  submitCheck() {
    let msg = this.data.msg
    let msgLength = msg.length
    let msg = this.data.msg;
    let msgLength = msg.length;
    //确认信息完整度
    for (let i = 0; i < msgLength; i++) {
      if (msg[i].required != false && msg[i].value === "") {
        let error = msg[i].name + "不可为空"
        let path = "msg[" + i + "].noValue"
      if (msg[i].required != false && msg[i].value === '') {
        let error = msg[i].name + '不可为空';
        let path = 'msg[' + i + '].noValue';
        this.setData({
          errorMsg: error,
          [path]: true
        })
          [path]: true,
        });
        wx.pageScrollTo({
          duration: 300,
          scrollTop: 0,
          // selector:"#" + msg[i].id,
        })
        return false
        });
        return false;
      }
      //身份证位数判断
      if (i == 4) {
        if (msg[i].value.length < msg[i].maxLength) {
          let error = msg[i].name + "位数错误"
          let path = "msg[" + i + "].noValue"
          let error = msg[i].name + '位数错误';
          let path = 'msg[' + i + '].noValue';
          this.setData({
            errorMsg: error,
            [path]: true
          })
            [path]: true,
          });
          return false
          return false;
        }
      }
    }
    var cList = []
    var cList = [];
    for (let i = 0; i < this.data.commitTypes.length; i++) {
      const t = this.data.commitTypes[i];
      if (t.checked) {
        cList.push(t)
        cList.push(t);
      }
    }
    if (cList.length == 0) {
      this.setData({
        errorMsg: '至少选择一项承诺类型',
      })
      return false
      });
      return false;
    }
    return true
  }
})
    return true;
  },
});