绿满眶商城微信小程序-uniapp
xiangpei
2025-05-26 86cbf346204232ba9a4ffea6fbcb4d9d2b521916
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
103
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
155
156
157
158
159
160
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<template>
  <div class="wrapper">
    <u-form label-width="200" :model="form" ref="uForm">
      <div class="column">
        <div class="flag-title light-color">基础信息</div>
        <u-form-item
          required
          :border-bottom="false"
          prop="storeName"
          label="店铺名称"
          ><u-input v-model="form.storeName" :custom-style="defaultInputStyle"
        /></u-form-item>
        <u-form-item
          required
          :border-bottom="false"
          prop="storeLogo"
          label="店铺logo"
        >
          <div>
            <u-upload
              :file-list="storeLogoFileList"
              :header="{ accessToken: storage.getAccessToken() }"
              :action="action"
              width="200"
              @on-uploaded="onUploaded($event, 'storeLogo')"
              :max-count="1"
              :show-progress="false"
            ></u-upload>
          </div>
        </u-form-item>
        <u-form-item
          required
          :border-bottom="false"
          prop="goodsManagementCategory"
          label="店铺经营类目"
          >
          <div @click="showCategory()"   style="margin-right: 30rpx;">选择</div>
         
          <u-input
            :custom-style="defaultInputStyle"
            v-model="goodsManagementCategory"
            disabled
            @click="showCategory()"
        /></u-form-item>
 
        <u-form-item
          required
          :border-bottom="false"
          prop="storeAddressPath"
          label="店铺所在地"
        >
          <div @click="showPicker()"   style="margin-right: 30rpx;">选择</div>
          <u-input
            :custom-style="defaultInputStyle"
            v-model="form.storeAddressPath"
          
            disabled
            
          />
        </u-form-item>
       
        <!-- <u-form-item
          required
          :border-bottom="false"
          prop="storeAddressPath"
          label="店铺定位"
        >
          <div class="get-center" @click="clickUniMap()">开始定位</div>
          <div class="tips-success" v-if="form.storeCenter">已成功定位</div>
        </u-form-item> -->
 
        <u-form-item
          required
          :border-bottom="false"
          prop="storeAddressDetail"
          label="店铺详细地址"
          ><u-input
            :custom-style="defaultInputStyle"
            v-model="form.storeAddressDetail"
        /></u-form-item>
        <u-form-item
          required
          :border-bottom="false"
          prop="storeDesc"
          label="店铺简介"
          ><u-input
            type="textarea"
            :custom-style="defaultInputStyle"
            v-model="form.storeDesc"
        /></u-form-item>
      </div>
    </u-form>
    <div class="submit" @click="validatorStep1Form">提交平台审核</div>
    <m-city
      :provinceData="list"
      headTitle="区域选择"
      ref="cityPicker"
      @funcValue="getPickerParentValue"
      pickerSize="4"
    >
    </m-city>
 
    <u-select
      v-model="enableCategory"
      @confirm="confirmCategory"
      :list="categoryList"
    ></u-select>
 
    <uniMap v-if="mapFlag" @close="closeMap" @callback="callBackAddress" />
  </div>
</template>
 
<script>
import UForm from '@/uview-components/uview-ui/components/u-form/u-form.vue';
import UFormItem from '@/uview-components/uview-ui/components/u-form-item/u-form-item.vue';
import UInput from '@/uview-components/uview-ui/components/u-input/u-input.vue';
import UUpload from '@/uview-components/uview-ui/components/u-upload/u-upload.vue';
import USelect from '@/uview-components/uview-ui/components/u-select/u-select.vue';
 
import { applyThird } from "@/api/entry";
import { getCategoryList } from "@/api/goods";
import city from "@/components/m-city/m-city.vue";
import storage from "@/utils/storage.js";
import { upload } from "@/api/common.js";
import uniMap from "@/components/uniMap";
import permision from "@/js_sdk/wa-permission/permission.js";
export default {
  components: { "m-city": city, uniMap, UForm,UFormItem,UInput,UUpload,USelect},
  data() {
    return {
      storage,
      mapFlag: false,
      action: upload, //图片上传数据
      defaultInputStyle: {
        background: "#f7f7f7",
        padding: "0 20rpx",
        "border-radius": "10rpx",
      },
      goodsManagementCategory: "",
      storeLogoFileList: [],
      categoryList: [],
      form: {
        storeName: "",
        storeLogo: "",
        goodsManagementCategory: "",
        storeAddressPath: "",
        storeAddressDetail: "",
        storeDesc: "",
      },
      list: [
        {
          id: "",
          localName: "请选择",
          children: [],
        },
      ],
      rules: {
        // 验证规则
        goodsManagementCategory: [
          { required: true, message: "请选择店铺经营类目" },
        ],
        storeName: [{ required: true, message: "请填写店铺名称" }],
        storeLogo: [{ required: true, message: "请上传店铺logo" }],
        storeDesc: [{ required: true, message: "请填写店铺简介" }],
        storeCenter: [{ required: true, message: "请选择店铺位置" }],
        storeAddressIdPath: [{ required: true, message: "请选择店铺位置" }],
        storeAddressDetail: [{ required: true, message: "请输入店铺详细地址" }],
      },
      enableCategory: false,
    };
  },
  mounted() {
    this.$refs.uForm.setRules(this.rules);
    this.fetchCategoryList();
  },
  props: ["companyData"],
  watch: {
    companyData: {
      handler(val) {
        this.$set(this, "form", val);
        // 给图片赋值
        const judgeDeepPhoto = ["storeLogo"];
 
        judgeDeepPhoto.forEach((key) => {
          if (this.form[key]) {
            this.form[key].split(",").forEach((item) => {
              this[`${key}FileList`].push({ url: item });
            });
          }
        });
      },
      deep: true,
      immediate: true,
    },
  },
 
  methods: {
    callBackAddress(val) {
      console.log(val);
      this.form.storeAddressDetail = val.address;
      this.form.storeCenter = `${val.longitude},${val.latitude}`;
    },
    // 关闭地图
    closeMap() {
      this.mapFlag = false;
    },
    // 打开地图并访问权限
    clickUniMap() {
      console.log("click");
      // #ifdef APP-PLUS
      if (plus.os.name == "iOS") {
        // ios系统
        permision.judgeIosPermission("location")
          ? (this.mapFlag = true)
          : this.refuseMap();
      } else {
        // 安卓
        this.requestAndroidPermission(
          "android.permission.ACCESS_FINE_LOCATION"
        );
      }
      // #endif
 
      // #ifndef APP-PLUS
      this.mapFlag = true;
      // #endif
    },
 
    // 如果拒绝权限 提示区设置
    refuseMap() {
      uni.showModal({
        title: "温馨提示",
        content: "您已拒绝定位,请开启",
        confirmText: "去设置",
        success(res) {
          if (res.confirm) {
            //打开授权设置
            // #ifndef MP-WEIXIN
            uni.getSystemInfo({
              success(res) {
                if (res.platform == "ios") {
                  //IOS
                  plus.runtime.openURL("app-settings://");
                } else if (res.platform == "android") {
                  //安卓
                  let main = plus.android.runtimeMainActivity();
                  let Intent = plus.android.importClass(
                    "android.content.Intent"
                  );
                  let mIntent = new Intent("android.settings.ACTION_SETTINGS");
                  main.startActivity(mIntent);
                }
              },
            });
            // #endif
          }
        },
      });
    },
    // 获取安卓是否拥有地址权限
    async requestAndroidPermission(permisionID) {
      var result = await permision.requestAndroidPermission(permisionID);
 
      if (result == 1) {
        this.mapFlag = true;
      } else {
        this.refuseMap();
      }
    },
 
    confirmCategory(val) {
      this.form.goodsManagementCategory = val[0].value;
      this.goodsManagementCategory = val[0].label;
    },
    async fetchCategoryList() {
      const res = await getCategoryList(0);
      if (res.data.success) {
        if (res.data.result.length) {
          this.categoryList = res.data.result.map((item) => {
            return { label: item.name, value: item.id };
          });
 
          if (this.form.goodsManagementCategory) {
            this.goodsManagementCategory = this.categoryList.find(
              (item) => this.form.goodsManagementCategory == item.value
            ).label;
          }
        }
      }
    },
    // 图片上传
    onUploaded(lists, key) {
      let images = [];
      lists.forEach((item) => {
        images.push(item.response.result);
      });
      this.form[key] = images;
    },
    getPickerParentValue(e) {
      this.form.storeAddressIdPath = [];
      console.log(e)
      let name = "";
      e.forEach((item, index) => {
        if (item.id) {
          // 遍历数据
          this.form.storeAddressIdPath.push(item.id);
          if (index == e.length - 1) {
            name += item.localName;
          } else {
            name += item.localName + ",";
          }
          this.$set(this.form,'storeAddressPath',name)
        }
      });
 
      this.form.storeCenter = e[e.length-1].center
    },
    // 显示三级地址联动
    showPicker() {
      this.$refs.cityPicker.show();
    },
    showCategory() {
      this.enableCategory = true;
    },
    validatorStep1Form() {
      this.$refs.uForm.validate(async (valid) => {
        console.log(valid);
        if (valid) {
          const params = { ...this.form };
          params.storeLogo = params.storeLogo.toString();
          params.storeAddressIdPath = params.storeAddressIdPath.toString();
          const res = await applyThird(params);
          if (res.data.success) {
            uni.showToast({
              title: "提交成功!",
              icon: "none",
            });
            this.$emit("callback");
          }
        }
      });
    },
  },
};
</script>
<style>
/* page {
  background: #fff;
} */
</style>
<style lang="scss" scoped>
@import url("./entry.scss");
.get-center {
  padding: 12rpx 30rpx;
  background: $light-color;
  border-radius: 10rpx;
  font-size: 24rpx;
  color: #fff;
  font-weight: bold;
  display: inline;
}
.column {
  padding: 32rpx;
  margin-bottom: 20rpx;
  background: #fff;
}
.submit {
  color: #fff;
  margin-top: 120rpx;
  background: rgba($light-color, 0.8);
}
.tips {
  color: #999;
  font-size: 24rpx;
  line-height: 1.2;
  margin-top: 10rpx;
}
.tips-success {
  color: $weChat-color;
  font-size: 24rpx;
}
</style>