StoreAddr.vue 6.41 KB
Newer Older
李嘉林 committed
1
<template>
李嘉林 committed
2
  <div class="storeAddr flex">
李嘉林 committed
3 4
    <div class="left flex">
      <div class="logo">
李嘉林 committed
5
        <image :src="logoUrl" alt=""></image>
李嘉林 committed
6 7 8 9 10 11 12 13 14 15 16
      </div>
      <div class="contentInfo flex" v-if="name != ''">
        <p class="info">{{ name }}</p>
        <p class="change" @click="pushStorePage">[切换]</p>
      </div>
    </div>
  </div>
</template>
<script>
import shop from "@/api/shop";
import { DFSImg } from "@/utils/index";
李嘉林 committed
17
import { setStoreInfo, getStoreInfo } from "@/utils/mayi"
李嘉林 committed
18
const app = getApp();
李嘉林 committed
19
const { log } = app;
李嘉林 committed
20 21 22 23 24 25 26 27 28
export default {
  data() {
    return {
      show: false,
      name: "",
      storeList: [],
      userLatitude: "", //纬度
      userLongitude: "", //经度
      offlineStoreReq: {
李嘉林 committed
29
        channelType: 2, //渠道类型(0:pc,1:app,2:小程序)
李嘉林 committed
30 31 32
        latitude: "",
        longitude: "",
        shopName: "",
李嘉林 committed
33 34
      },
      enterShopId: "", //进店规则门店id
李嘉林 committed
35 36
      logoUrl: "",
      openThousandsStoresFlag: false,
李嘉林 committed
37 38
    };
  },
李嘉林 committed
39 40 41 42 43 44 45 46
  async onLoad() {
    let shopInfo = await shop.getShopInfo(JSON.parse(wx.getStorageSync("extConfig")));
    console.log(shopInfo,'-------------shopInfo')
    if (shopInfo.data.code == 200) {
      this.openThousandsStoresFlag = shopInfo.data.data.openThousandsStoresFlag == 1;
      this.logoUrl = DFSImg(shopInfo.data.data.logoUrl, 400, 400);
      console.log(this.openThousandsStoresFlag,this.logoUrl,'-------------shopInfo')
    }
李嘉林 committed
47 48 49 50 51
    if (this.openThousandsStoresFlag) {
      this.getLocationHandle(() => {
        this.getShopList();
      });
    }
李嘉林 committed
52 53
    let { offlineShopName } = getStoreInfo();
    this.name = offlineShopName || "";
李嘉林 committed
54 55 56 57
  },
  computed: {
  },
  methods: {
李嘉林 committed
58 59 60
    getLocationHandle(callback) {
      let _this = this;
      wx.getLocation({
李嘉林 committed
61 62
        type: "gcj02", // gcj02 wgs84
        isHighAccuracy: true,
李嘉林 committed
63 64 65 66
        success: res => {
          // latitude longitude speed accuracy
          log.info("~~~~~~~~~1~~~~~~~", res);
          console.log("~~~~~~~~~1~~~~~~~", res);
李嘉林 committed
67 68
          _this.offlineStoreReq.latitude = res.latitude;
          _this.offlineStoreReq.longitude = res.longitude;
李嘉林 committed
69 70 71 72 73 74 75 76 77 78 79 80 81
          // 存缓存
          wx.setStorageSync("locationObj", JSON.stringify(res));
          callback(res);
        },
        fail: res => {
          log.info("++++++++++2++++++", res);
          console.log("++++++++++2++++++", res);
          wx.setStorageSync("locationObj", "");
          callback(res);
        }
      });
    },
    async getShopList() {
李嘉林 committed
82 83 84 85 86 87 88 89
      if (!this.openThousandsStoresFlag) {
        // 未开启连锁商城初始化
        setStoreInfo({
          offlineShopCode: "",
          offlineShopName: "",
        });
        return;
      };
李嘉林 committed
90
      return;
李嘉林 committed
91 92 93
      // 进店规则获取门店id
      let query = {
        channelType: 2, //设备类型(0:pc,1:app,2:小程序)
李嘉林 committed
94 95
        consumerLongitude: this.offlineStoreReq.longitude, //经度,小程序和app可以获取到就要传,没有不传
        consumerLatitude: this.offlineStoreReq.latitude, //纬度,小程序和app可以获取到就要传,没有不传
李嘉林 committed
96
        distributionOfficerShopcode: "" //分销员门店id,没有不传
李嘉林 committed
97 98 99 100 101 102
      }
      let enterShopRes = await shop.getEnterShopId(query);
      if (enterShopRes && enterShopRes.code == 200) {
        this.enterShopId = enterShopRes.data;
      }
      shop.changingOverShopForXinHua(this.offlineStoreReq).then(res1 => {
李嘉林 committed
103 104 105 106 107 108
        let res = res1.data;
        if (res.code == 200) {
          if (res.data && res.data.length != 0) {
            this.storeList = res.data;
            let isStore = false;
            let { offlineShopName, offlineShopCode } = getStoreInfo();
李嘉林 committed
109
            console.log(offlineShopName, offlineShopCode, '------------------sa114')
李嘉林 committed
110
            if (this.enterShopId) {
李嘉林 committed
111 112
              // 如果有进店规则门店id则直接匹配存入
              let ruleShop = this.storeList.filter(item => item.id == this.enterShopId);
李嘉林 committed
113 114
              if (ruleShop && ruleShop.length > 0) {
                this.name = ruleShop[0].shopName;
李嘉林 committed
115 116 117 118 119 120
                this.$store.dispatch("setShopCode", {
                  shopCode: ruleShop[0].shopCode,
                });
                this.$store.dispatch("setShopName", {
                  shopName: ruleShop[0].shopName,
                });
李嘉林 committed
121
                this.$emit("toUpdate");
李嘉林 committed
122
                return;
李嘉林 committed
123 124
              }
            }
李嘉林 committed
125 126 127 128 129 130 131 132 133 134 135
            this.storeList.forEach((item, index) => {
              if (item.shopName == offlineShopName) {
                isStore = true;
              } else if (offlineShopCode == "") {
                isStore = true;
              }
            });
            console.log(offlineShopName, isStore, "sa97");
            if (offlineShopName && isStore) {
              console.log("判断列表中是否存在(未关闭网店)");
              this.name = offlineShopName;
李嘉林 committed
136
              this.$emit("toUpdate");
李嘉林 committed
137 138 139 140 141 142 143
            } else {
              console.log("如果关闭网店,重新选择列表第一个");
              setStoreInfo({
                offlineShopCode: this.storeList[0].shopCode,
                offlineShopName: this.storeList[0].shopName,
              });
              this.name = this.storeList[0].shopName;
李嘉林 committed
144
              this.$emit("toUpdate");
李嘉林 committed
145 146 147 148 149 150 151 152
            }
          } else {
            console.log("如果列表为空--选择商城");
            setStoreInfo({
              offlineShopCode: "",
              offlineShopName: this.shopName,
            });
            this.name = this.shopName;
李嘉林 committed
153
            this.$emit("toUpdate");
李嘉林 committed
154 155 156 157 158 159
          }
        }
      });
    },
    // 去切换门店页面
    pushStorePage() {
李嘉林 committed
160
      this.$emit("toPageLoading");
李嘉林 committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
      app.$themeToLink({
        type: 1,
        link: `/chooseStores`,
      })
    }
  }
};
</script>
<style lang="scss" scoped>
.storeAddr {
  padding: 6px 12px;
  justify-content: space-between;

  .left,
  .right {
    align-items: center;

    i.iconfont {
      font-size: 22px;
      margin: 0 5px;
    }
  }

  .left {
    align-items: center;

    .contentInfo {
      align-items: flex-start;

      .info {
        font-size: 14px;
        color: #999;
        flex: 1;
      }

      .change {
        flex-shrink: 0;
        padding-left: 6px;
        color: #333;
        font-size: 14px;
      }

    }

    .logo {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      overflow: hidden;
      margin-right: 10px;

      image {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
  }

  .right {
    i.iconfont {
      font-size: 24px;
    }
  }
}
</style>