|
@@ -1,4 +1,6 @@
|
|
|
const uploadJS = require('../../mixin/upload.js')
|
|
|
+const { userApplyShop } = require('./api/index')
|
|
|
+const { isMobile } = require('../../utils/validate')
|
|
|
|
|
|
Page({
|
|
|
|
|
@@ -7,17 +9,26 @@ Page({
|
|
|
*/
|
|
|
data: {
|
|
|
form: {
|
|
|
- name: '',
|
|
|
- card_id: '',
|
|
|
- phone: '',
|
|
|
- partner_name: '',
|
|
|
- wx_code: [],
|
|
|
- wxid: '',
|
|
|
- address: {},
|
|
|
- note: ''
|
|
|
- }
|
|
|
+ 'user_name': '', // 用户姓名
|
|
|
+ 'shop_name': '', // 店铺名称
|
|
|
+ 'user_card': '', // 身份证
|
|
|
+ 'shop_phone': '', // 手机号码
|
|
|
+ 'country_msg': '', // 乡村信息
|
|
|
+ 'user_code_url': [], // 微信二维码
|
|
|
+ 'user_wechat_code': '', // 微信号
|
|
|
+ 'shop_img_url': [], // 店铺图片地址
|
|
|
+ 'shop_address': {
|
|
|
+ 'longitude': 0, // 经度
|
|
|
+ 'latitude': 0, // 纬度
|
|
|
+ 'address_name': '', // 起点位置名称
|
|
|
+ 'name': ''
|
|
|
+ }, // 店铺地址
|
|
|
+ 'shop_remark': '' // 备注
|
|
|
+ },
|
|
|
+ booLock: false
|
|
|
},
|
|
|
-
|
|
|
+ tempFormKey: '',
|
|
|
+ tempPostData: {},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
@@ -51,27 +62,6 @@ Page({
|
|
|
*/
|
|
|
onUnload() {
|
|
|
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 页面相关事件处理函数--监听用户下拉动作
|
|
|
- */
|
|
|
- onPullDownRefresh() {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 页面上拉触底事件的处理函数
|
|
|
- */
|
|
|
- onReachBottom() {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 用户点击右上角分享
|
|
|
- */
|
|
|
- onShareAppMessage() {
|
|
|
-
|
|
|
},
|
|
|
...uploadJS,
|
|
|
uploadCallBack(res) {
|
|
@@ -88,12 +78,9 @@ Page({
|
|
|
}
|
|
|
|
|
|
switch (formkey) {
|
|
|
- case 'product_img_url':
|
|
|
- tempForm[`form.${formkey}`] = temp
|
|
|
- break
|
|
|
- case 'product_rotation_img_list':
|
|
|
- case 'product_detail_img_list':
|
|
|
- tempForm[`form.${formkey}`] = this.data.form[formkey].concat(...temp)
|
|
|
+ case 'user_code_url':
|
|
|
+ case 'shop_img_url':
|
|
|
+ tempForm[`form.${formkey}[0]`] = temp[0]
|
|
|
break
|
|
|
default:
|
|
|
}
|
|
@@ -101,5 +88,221 @@ Page({
|
|
|
if (Object.keys(tempForm).length > 0) {
|
|
|
this.setData(tempForm)
|
|
|
}
|
|
|
+ },
|
|
|
+ setFormValue(event) {
|
|
|
+ const { value } = event.detail
|
|
|
+ const { formkey } = event.target.dataset
|
|
|
+ let tempForm = {}
|
|
|
+
|
|
|
+ switch (formkey) {
|
|
|
+ case 'user_name':
|
|
|
+ case 'shop_name':
|
|
|
+ case 'user_card':
|
|
|
+ case 'country_msg':
|
|
|
+ case 'user_wechat_code':
|
|
|
+ case 'shop_remark':
|
|
|
+ tempForm[`form.${formkey}`] = value
|
|
|
+ break
|
|
|
+ case 'shop_phone':
|
|
|
+ tempForm[`form.${formkey}`] = value.replace(/[^\d]$/, '').replace(/^0/, '').replace(/(\d{11}(.*))/, '$1')
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData(tempForm)
|
|
|
+ },
|
|
|
+ // 获取定位权限、定位权限授权
|
|
|
+ async handleGetSetting() {
|
|
|
+ const that = this
|
|
|
+
|
|
|
+ try {
|
|
|
+ const { errMsg, authSetting } = await wx.getSetting()
|
|
|
+ if (errMsg === 'getSetting:ok') {
|
|
|
+ // 有定位授权
|
|
|
+ if (authSetting['scope.userLocation']) {
|
|
|
+ if (that.tempFormKey === '') {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ await that.chooseLocationBridge()
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (err) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ await wx.authorize({ scope: 'scope.userLocation' })
|
|
|
+ if (that.tempFormKey === '') {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ await that.chooseLocationBridge()
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '未开启获取地理位置权限,去设置中打开',
|
|
|
+ success(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ that.openSetting()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 去小程序自带设置页:返回
|
|
|
+ async openSetting() {
|
|
|
+ try {
|
|
|
+ const openSettingData = await wx.openSetting()
|
|
|
+ // 开启了定位权限
|
|
|
+ if (openSettingData.authSetting['scope.userLocation']) {
|
|
|
+ if (this.tempFormKey === '') {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ await this.chooseLocationBridge()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (err) {}
|
|
|
+ },
|
|
|
+ async handleChooseLocation(e) {
|
|
|
+ const { lat, lon, formkey } = e.currentTarget.dataset
|
|
|
+ this.tempPostData = lat && lon ? {
|
|
|
+ latitude: lat,
|
|
|
+ longitude: lon
|
|
|
+ } : {}
|
|
|
+ this.tempFormKey = 'form.' + formkey
|
|
|
+ await this.handleGetSetting()
|
|
|
+ },
|
|
|
+ async chooseLocationBridge() {
|
|
|
+ if (!this.tempFormKey) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const { errMsg, address, latitude, longitude, name } = await wx.chooseLocation(this.tempPostData)
|
|
|
+ if (errMsg === 'chooseLocation:ok' && address && name) {
|
|
|
+ const pointInfo = {
|
|
|
+ address_name: address,
|
|
|
+ name,
|
|
|
+ latitude,
|
|
|
+ longitude
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ [this.tempFormKey]: pointInfo
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ // 点击了取消按钮
|
|
|
+ if (err.errMsg === 'chooseLocation:fail cancel') {
|
|
|
+ }
|
|
|
+ // 未开启授权
|
|
|
+ if (err.errMsg === 'chooseLocation:fail auth deny') {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getForm() {
|
|
|
+ const {
|
|
|
+ user_name,
|
|
|
+ shop_name,
|
|
|
+ user_card,
|
|
|
+ shop_phone,
|
|
|
+ country_msg,
|
|
|
+ user_code_url,
|
|
|
+ user_wechat_code,
|
|
|
+ shop_img_url,
|
|
|
+ shop_address,
|
|
|
+ shop_remark
|
|
|
+ } = this.data.form
|
|
|
+
|
|
|
+ return {
|
|
|
+ user_name,
|
|
|
+ shop_name,
|
|
|
+ user_card,
|
|
|
+ shop_phone,
|
|
|
+ country_msg,
|
|
|
+ user_code_url: user_code_url.map(item => item.url).join(''),
|
|
|
+ user_wechat_code,
|
|
|
+ shop_img_url: shop_img_url.map(item => item.url).join(''),
|
|
|
+ shop_address,
|
|
|
+ shop_remark
|
|
|
+ }
|
|
|
+ },
|
|
|
+ verify() {
|
|
|
+ let errorList = []
|
|
|
+ const {
|
|
|
+ user_name,
|
|
|
+ shop_name,
|
|
|
+ user_card,
|
|
|
+ shop_phone,
|
|
|
+ country_msg,
|
|
|
+ user_code_url,
|
|
|
+ user_wechat_code,
|
|
|
+ shop_img_url,
|
|
|
+ shop_address,
|
|
|
+ shop_remark
|
|
|
+ } = this.getForm()
|
|
|
+
|
|
|
+ if (!user_name) {
|
|
|
+ errorList.push('请输入姓名')
|
|
|
+ }
|
|
|
+ if (!user_card) {
|
|
|
+ errorList.push('请输入身份证号码')
|
|
|
+ }
|
|
|
+ if (!isMobile(shop_phone)) {
|
|
|
+ errorList.push('请输入手机号')
|
|
|
+ }
|
|
|
+ if (!country_msg) {
|
|
|
+ errorList.push('请输入村信息')
|
|
|
+ }
|
|
|
+ if (!user_code_url) {
|
|
|
+ errorList.push('请上传个人二维码')
|
|
|
+ }
|
|
|
+ if (!user_wechat_code) {
|
|
|
+ errorList.push('请输入微信号')
|
|
|
+ }
|
|
|
+ if (!shop_name) {
|
|
|
+ errorList.push('请输入店铺名称')
|
|
|
+ }
|
|
|
+ if (!shop_img_url) {
|
|
|
+ errorList.push('请上传店铺图片')
|
|
|
+ }
|
|
|
+ if (!shop_address.address_name) {
|
|
|
+ errorList.push('请选择详细地址')
|
|
|
+ }
|
|
|
+ if (!shop_remark) {
|
|
|
+ errorList.push('请输入备注')
|
|
|
+ }
|
|
|
+
|
|
|
+ return errorList
|
|
|
+ },
|
|
|
+ async onSubmit() {
|
|
|
+ const temp = this.getForm()
|
|
|
+ const verifyList = this.verify()
|
|
|
+
|
|
|
+ if (verifyList.length) {
|
|
|
+ wx.showToast({
|
|
|
+ title: verifyList[0],
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ booLock: true
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ const { status, data, msg } = await userApplyShop(temp)
|
|
|
+ if (status) {
|
|
|
+ wx.switchTab({
|
|
|
+ url: '/pages/mine/mine'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (err) {}
|
|
|
+ this.setData({
|
|
|
+ booLock: false
|
|
|
+ })
|
|
|
}
|
|
|
})
|