| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- import { FunCode } from "../../../../constants/enum/funcode"
- import { sendMsgToMQ } from "../../../../services/api/common/index"
- import { divisions, isEncrypted, protoHeader, userid, timetample } from '../../../../services/utils'
- import { areaList } from '@vant/area-data';
- import Toast from "../../../../miniprogram_npm/@vant/weapp/toast/toast";
- import { hideLoading, showLoading } from "../../../../utils/message/index";
- /// regions
- const regions = divisions()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- /// 收货人姓名
- username: '',
- /// 电话好嘛
- mobile: '',
- /// 详细收货地址
- detailAddress: '',
- /// 显示地址
- region: '请选择地区',
- /// 省份地区
- province: 0,
- /// 市
- city: 0,
- /// 区、乡镇
- country: 0,
- /// 是否选择地区
- show: false,
- /// 省市区数据
- areaList,
- /// 自增id
- autoid: 0,
- /// 是否默认
- check: true
- },
- /// 关闭地址选择组件
- cancelArea() {
- /// 关闭
- this.setData({ show: false })
- },
- /// 确认地址选择组件
- confirmArea(e: any) {
- /// 区、乡镇
- const c = regions.filter(obj => { return obj.divisioncode == e.detail.values[2].code })[0]
- /// 关闭
- this.setData({
- /// 不显示
- show: false,
- /// 省份
- province: regions.filter(obj => {
- return obj.divisioncode == e.detail.values[0].code
- })[0].autoid,
- /// 城市
- city: regions.filter(obj => {
- return obj.divisioncode == e.detail.values[1].code
- })[0].autoid,
- /// 区、乡镇
- country: c.autoid,
- /// 选择地区
- region: c.pathname
- })
- },
- /**
- * 返回上层视图
- */
- backToParent() {
- /// 返回上层视图
- wx.navigateBack()
- },
- /**
- * 按钮点击响应事件
- */
- onButtonPressed(e: any) {
- switch (e.target.id) {
- case "region-selsct": /// 地区选择
- if (!this.data.show) { this.setData ({ show: true }) }
- break;
- case "delete": /// 删除
- this.deleteReciveInfoReq()
- break
- default:
- /// 发送业务操作
- this.userReciveInfoReq()
- break;
- }
- },
-
- /**
- * 开关响应事件
- */
- onChange({ detail }){
- // 需要手动对 checked 状态进行更新
- this.setData({ checked: detail });
- /// 设为默认
- if (!this.data.check) {
- this.receiveIsDefaultReq()
- }
- },
- /// 合规性校验
- check(): boolean {
- /// 请输入用户名
- if (this.data.username.length == 0) {
- Toast('请输入用户名!')
- return false
- }
- /// 请输入收货人手机号码
- if (this.data.mobile.length == 0) {
- Toast('请输入收货人手机号码!')
- return false
- }
- /// 请输入选择地区
- if (this.data.province == 0) {
- Toast('请输入选择地区!')
- return false
- }
-
- /// 请输入详细地址信息
- if (this.data.detailAddress.length == 0) {
- Toast('请输入详细地址信息!')
- return false
- }
- return true
- },
- /**
- * 删除收货地址信息
- */
- deleteReciveInfoReq() {
- /// loding.....
- showLoading(()=>{
- /// 参数信息
- const userInfo = {
- ReceiveInfoId: this.data.autoid,
- Header: protoHeader(FunCode.DelUserReceiveInfoReq)
- }
- /// 发送请求
- sendMsgToMQ({
- data: {
- data: JSON.stringify(userInfo),
- funCodeReq: FunCode.DelUserReceiveInfoReq,
- funCodeRsp: FunCode.DelUserReceiveInfoRsp,
- isEncrypted: isEncrypted()
- },
- success: (res) => {
- /// 操作失败
- if (res.code != 0) {
- hideLoading(()=>{}, '删除操作失败,原因:'+res.msg, 'error')
- return
- }
- /// 操作成功
- hideLoading(()=>{
- /// 返回上层视图
- wx.navigateBack()
- }, '删除操作成功', 'success')
- },
- fail: (emsg) => {
- /// 操作失败
- hideLoading(()=>{}, '删除操作失败,原因:'+emsg, 'error')
- }
- })
- }, '删除操作请求中.....')
- },
- /**
- * 将收货地址设为默认
- */
- receiveIsDefaultReq() {
- /// loding.....
- showLoading(()=> {
- /// 参数信息
- const data = {
- AutoId: this.data.autoid,
- UserId: userid(),
- Header: protoHeader(FunCode.UserReceiveIsDefaultReq)
- }
- /// 发送请求
- sendMsgToMQ({
- data: {
- data: JSON.stringify(data),
- funCodeReq: FunCode.UserReceiveIsDefaultReq,
- funCodeRsp: FunCode.UserReceiveIsDefaultRsp,
- isEncrypted: isEncrypted()
- },
- success: (res) => {
- /// 操作失败
- if (res.code != 0) {
- hideLoading(()=>{}, '操作失败,原因:'+res.msg, 'error')
- return
- }
- hideLoading(()=>{
- /// 返回上层视图
- wx.navigateBack()
- }, '操作成功', 'success')
- },
- fail: (emsg) => {
- /// 操作失败
- hideLoading(()=>{}, '操作失败,原因:'+emsg, 'error')
- }
- })
- })
- },
- /**
- * 业务操作
- */
- userReciveInfoReq() {
- /// 合规性校验
- if (!this.check()) { return }
- /// loding.....
- showLoading(()=> {
- /// 参数信息
- const userInfo = { ClientSerialID: timetample(),
- UserID: userid(),
- ReceiverName: this.data.username,
- CardTypeID: 0,
- CardNum: '0',
- PhoneNum: this.data.mobile,
- CountryID: 0,
- ProvinceID: this.data.province,
- CityID: this.data.city,
- DistrictID: this.data.country,
- Address: this.data.detailAddress,
- TakeRemark: '',
- ReceiveInfoId: this.data.autoid,
- Header: protoHeader(FunCode.UserReceiveInfoReq)
- }
- /// 发送请求
- sendMsgToMQ({
- data: {
- data: JSON.stringify(userInfo),
- funCodeReq: FunCode.UserReceiveInfoReq,
- funCodeRsp: FunCode.UserReceiveInfoRsp,
- isEncrypted: isEncrypted()
- },
- success: (res) => {
- /// 操作失败
- if (res.code != 0) {
- hideLoading(()=>{}, '操作失败,原因:'+res.msg, 'error')
- return
- }
- /// 操作失败
- hideLoading(()=>{
- /// 返回上层视图
- wx.navigateBack()
- }, '操作成功', 'success')
- },
- fail: (emsg) => {
- /// 操作失败
- hideLoading(()=>{}, '操作失败,原因:'+emsg, 'error')
- }
- })
- }, '操作请求中......')
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options: any) {
- /// 传参信息
- const d: GuangZuan.UserReceiveInfo = JSON.parse(options.id ?? '')
- this.setData({
- username: d.receivername,
- mobile: d.phonenum,
- province: d.provinceid,
- city: d.cityid,
- country: d.districtid,
- detailAddress: d.address,
- autoid: d.autoid,
- region: d.provincename+d.cityname+d.countryname,
- check: d.isdefault == 1
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {},
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {},
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {}
- })
|