| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- // prsx/select/area/index.js
- const _Http = getApp().globalData.http;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- popupShow: false,
- result: [], //返回结果
- radio: false, //是否为单选
- idname: "sa_saleareaid", //idkey
- showName: "sa_saleareaid", //表单用 显示名称
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- console.log(options, 'options数据')
- this.setData({
- popupShow: true
- })
- _Http.basic({
- "content": {},
- "classname": "webmanage.sale.salearea.salearea",
- "method": "query_area"
- }).then(res => {
- if (res.code != '1') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- console.log(res.data, '输出区域数据')
- let list = res.data.map(v => {
- v.subarea.unshift({
- areaname: v.areaname + ' (不含下级)',
- sa_saleareaid: v.sa_saleareaid
- })
- return {
- id: v.sa_saleareaid,
- text: v.areaname,
- children: v.subarea.map(value => {
- const text = value.areaname;
- if (value.sa_saleareaid == wx.getStorageSync('userMsg').sa_saleareaid) this.setData({
- sa_saleareaid: value.sa_saleareaid,
- activeId: value.sa_saleareaid,
- text: value.areaname,
- showText: value.areaname
- })
- return {
- id: value.sa_saleareaid,
- text
- }
- })
- }
- })
- this.setData({
- list,
- radio: options.radio ? true : false,
- idname: options.idname || this.data.idname,
- showName: options.showName || this.data.showName
- })
- });
- },
- onClickNav({
- detail
- }) {
- this.setData({
- mainActiveIndex: detail.index
- })
- },
- // onClickItem({
- // detail
- // }) {
- // this.setData({
- // sa_saleareaid: detail.id,
- // activeId: detail.id,
- // text: detail.text
- // })
- // },
- /* 选中 */
- onClickItem(e) {
- console.log(e,'输出e的数据')
- console.log(this.data.result,'输出result')
- let {
- id
- } = e.detail, result = this.data.result;
- console.log(id,'输出id的数据')
- if (this.data.radio) {
- result = [id];
- } else {
- result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
- }
- this.setData({
- sa_saleareaid: e.detail.id,
- activeId: e.detail.id,
- text: e.detail.text,
- popupShow:false,
- result
- });
- if (this.data.radio) this.submit();
- },
- /* 提交 */
- submit() {
- let result = this.data.result,
- obj = this.data.radio ? {
- id: result,
- item: this.data,
- value: [this.data.text, result]
- } : {
- result,
- list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
- value: [result.map(v => {
- let data = this.data.list.find(value => value[this.data.idname] == v);
- return data ? data[this.data.showName] : ""
- }), result]
- }
- wx.navigateBack()
- getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
- },
- onClose() {
- this.setData({
- popupShow: false
- })
- wx.navigateBack()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|