Blame view

src/component/tips-nearby-store-comp/tips-nearby-store-comp.js 5.78 KB
simon committed
1 2 3 4 5
import {
  getBindtapData,
} from '../../utils/util';
let app = getApp();

simon committed
6 7 8 9 10 11
Component({
  properties: {
    // 这里定义了innerText属性,属性值可以在组件使用时指定
    innerText: {
      type: String,
      value: 'default value',
simon committed
12 13 14 15 16 17 18 19 20 21 22 23 24
    },
    wishInfo: {
      type: Object,
      value: {},
    },
    location: {
      type: Object,
      value: {},
    },
    //是否选择模式
    selectedMode: {
      type: Boolean,
      value: false
simon committed
25 26 27 28
    }
  },
  data: {
    // 这里是一些组件内部数据
simon committed
29 30 31 32 33 34 35 36
    someData: {},
    searchMode: 1, // 查询模式 1.根据位置自动查询 2.省市区查询
    provinceId: "",
    cityId: "",
    districtId: "",
    provinceList: [],
    cityList: [],
    districtList: [],
1  
simon committed
37 38 39
    provinceIndex: -1,
    cityIndex: -1,
    districtIndex: -1,
simon committed
40 41
    addressList: [],
    total: 0,
simon committed
42 43
    curAddress: null,
    localCity: ""
simon committed
44 45
  },
  methods: {
simon committed
46 47 48 49
    /**
     * 请求门店地址
     */
    queryShop() {
simon committed
50 51 52
      this.setData({
        curAddress: ""
      })
simon committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
      return new Promise((resolve, reject) => {
        let {
          location,
          wishInfo,
          provinceId,
          cityId,
          districtId,
        } = this.data;
        app.post({
          url: app.api.storeQuery,
          data: {
            couponId: wishInfo.couponId,
            latitude: location.latitude,
            longitude: location.longitude,
            provinceId: provinceId,
            cityId: cityId,
            districtId: districtId,
            page: 1,
            size: 100,
          }
        }).then((result) => {
          this.setData({
            addressList: result.list,
simon committed
76 77
            total: result.total,
            localCity: result.city
simon committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
          })
          resolve();
        })
      });
    },

    /**
     * 选择地址 item
     */
    onSelectHandler(evt) {
      let item = getBindtapData(evt);
      let index = getBindtapData(evt, "index");
      let addressList = this.data.addressList;
      addressList.forEach((element, idx) => {
        element.selected = index == idx;
      });

      this.setData({
        addressList: addressList,
        curAddress: item
      })
    },

    /**
     * 提交门店
simon committed
103
     * 预约
simon committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
     */
    onSubmitHandler(evt) {
      let curAddress = this.data.curAddress;
      if (!curAddress) {
        wx.showToast({
          title: "请选择门店",
          icon: 'none'
        });
        return;
      }
      let wishInfo = this.properties.wishInfo;
      app.post({
        url: app.api.wishbillStoreAppoint,
        data: {
          instanceCode: wishInfo.instanceCode,
          storeCode: curAddress.storeCode,
          storeName: curAddress.storeName,
          storeAddress: curAddress.storeAddress,
          latitude: curAddress.latitude,
          longitude: curAddress.longitude
        }
      }).then((result) => {
        this.triggerEvent('evtcomp', {
          name: "_evt_submit_store_complete"
        })
      });
    },

    /**
     * 显示位置
     * @param {*} e
     */
    onShowLocHandler(evt) {
      let item = getBindtapData(evt);
      wx.openLocation({
        latitude: item.latitude, // 纬度,范围为-90~90,负数表示南纬
        longitude: item.longitude, // 经度,范围为-180~180,负数表示西经
        scale: 18, // 缩放比例
        name: item.storeName, // 位置名
        address: item.storeAddress, // 地址的详细说明
        success: function (res) {
          // success
        }
      })
    },

    // 转换成手动模式
    onSearchHandModeHandler() {
      this.setData({
        searchMode: 2
      });
simon committed
155
      this.queryShop();
simon committed
156 157 158 159 160 161 162 163 164 165
    },

    // 转换为自动模式
    onSearchAutoModeHandler() {
      this.setData({
        searchMode: 1,
        provinceId: "",
        cityId: "",
        districtId: "",
      })
simon committed
166
      this.queryShop();
simon committed
167 168 169 170 171 172 173 174 175 176
    },

    getProvince() {
      return new Promise((resolve, reject) => {
        app.post({
          url: app.api.provinceQuery
        }).then((result) => {
          this.setData({
            provinceList: result
          })
1  
simon committed
177
          // console.log("getProvince result:", result);
simon committed
178 179 180 181 182 183 184 185 186 187 188 189
        })
      });
    },

    getCity() {
      return new Promise((resolve, reject) => {
        app.post({
          url: app.api.cityQuery,
          data: {
            parentId: this.data.provinceId
          }
        }).then((result) => {
simon committed
190 191 192
          this.setData({
            cityList: result
          })
simon committed
193 194 195 196 197 198 199 200 201 202 203 204
        })
      });
    },

    getDistrict() {
      return new Promise((resolve, reject) => {
        app.post({
          url: app.api.districtQuery,
          data: {
            parentId: this.data.cityId
          }
        }).then((result) => {
simon committed
205 206 207
          this.setData({
            districtList: result
          })
simon committed
208 209 210 211 212 213 214 215 216 217
        })
      });
    },

    bindPickerChangeProvince(e) {
      let index = e.detail.value;
      this.setData({
        provinceIndex: index,
        provinceId: this.data.provinceList[index].id,
        cityList: [],
simon committed
218
        cityIndex: -1,
simon committed
219
        districtList: [],
simon committed
220
        districtIndex: -1,
simon committed
221
      })
simon committed
222
      this.getCity();
simon committed
223 224 225 226 227 228 229 230
    },

    bindPickerChangeCity(e) {
      let index = e.detail.value;
      this.setData({
        cityIndex: index,
        cityId: this.data.cityList[index].id,
        districtList: [],
simon committed
231
        districtIndex: -1,
simon committed
232 233 234 235 236 237 238 239 240 241
      })
      this.getDistrict();
    },

    bindPickerChangeDistrict(e) {
      let index = e.detail.value;
      this.setData({
        districtIndex: index,
        districtId: this.data.districtList[index].id,
      })
simon committed
242
      this.queryShop();
simon committed
243 244 245 246
    },



simon committed
247 248 249 250 251 252 253 254 255 256 257 258
    // 这里是一个自定义方法
    customMethod() {
      this.triggerEvent('evtcomp', {
        name: "_evt_custom"
      })
    },
    // 隐藏蒙层
    hideMask() {
      this.triggerEvent('evtcomp', {
        name: "_evt_hide_mask"
      });
    }
simon committed
259 260 261 262
  },
  //
  ready() {
    this.getProvince();
simon committed
263 264
  }
})