index.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import { FunCode } from "../../../../constants/enum/funcode"
  2. import { sendMsgToMQ } from "../../../../services/api/common/index"
  3. import { divisions, isEncrypted, protoHeader, userid, timetample } from '../../../../services/utils'
  4. import { areaList } from '@vant/area-data';
  5. import Toast from "../../../../miniprogram_npm/@vant/weapp/toast/toast";
  6. import { hideLoading, showLoading } from "../../../../utils/message/index";
  7. /// regions
  8. const regions = divisions()
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. /// 收货人姓名
  15. username: '',
  16. /// 电话好嘛
  17. mobile: '',
  18. /// 详细收货地址
  19. detailAddress: '',
  20. /// 显示地址
  21. region: '请选择地区',
  22. /// 省份地区
  23. province: 0,
  24. /// 市
  25. city: 0,
  26. /// 区、乡镇
  27. country: 0,
  28. /// 是否选择地区
  29. show: false,
  30. /// 省市区数据
  31. areaList,
  32. /// 自增id
  33. autoid: 0,
  34. /// 是否默认
  35. check: true
  36. },
  37. /// 关闭地址选择组件
  38. cancelArea() {
  39. /// 关闭
  40. this.setData({ show: false })
  41. },
  42. /// 确认地址选择组件
  43. confirmArea(e: any) {
  44. /// 区、乡镇
  45. const c = regions.filter(obj => { return obj.divisioncode == e.detail.values[2].code })[0]
  46. /// 关闭
  47. this.setData({
  48. /// 不显示
  49. show: false,
  50. /// 省份
  51. province: regions.filter(obj => {
  52. return obj.divisioncode == e.detail.values[0].code
  53. })[0].autoid,
  54. /// 城市
  55. city: regions.filter(obj => {
  56. return obj.divisioncode == e.detail.values[1].code
  57. })[0].autoid,
  58. /// 区、乡镇
  59. country: c.autoid,
  60. /// 选择地区
  61. region: c.pathname
  62. })
  63. },
  64. /**
  65. * 返回上层视图
  66. */
  67. backToParent() {
  68. /// 返回上层视图
  69. wx.navigateBack()
  70. },
  71. /**
  72. * 按钮点击响应事件
  73. */
  74. onButtonPressed(e: any) {
  75. switch (e.target.id) {
  76. case "region-selsct": /// 地区选择
  77. if (!this.data.show) { this.setData ({ show: true }) }
  78. break;
  79. case "delete": /// 删除
  80. this.deleteReciveInfoReq()
  81. break
  82. default:
  83. /// 发送业务操作
  84. this.userReciveInfoReq()
  85. break;
  86. }
  87. },
  88. /**
  89. * 开关响应事件
  90. */
  91. onChange({ detail }){
  92. // 需要手动对 checked 状态进行更新
  93. this.setData({ checked: detail });
  94. /// 设为默认
  95. if (!this.data.check) {
  96. this.receiveIsDefaultReq()
  97. }
  98. },
  99. /// 合规性校验
  100. check(): boolean {
  101. /// 请输入用户名
  102. if (this.data.username.length == 0) {
  103. Toast('请输入用户名!')
  104. return false
  105. }
  106. /// 请输入收货人手机号码
  107. if (this.data.mobile.length == 0) {
  108. Toast('请输入收货人手机号码!')
  109. return false
  110. }
  111. /// 请输入选择地区
  112. if (this.data.province == 0) {
  113. Toast('请输入选择地区!')
  114. return false
  115. }
  116. /// 请输入详细地址信息
  117. if (this.data.detailAddress.length == 0) {
  118. Toast('请输入详细地址信息!')
  119. return false
  120. }
  121. return true
  122. },
  123. /**
  124. * 删除收货地址信息
  125. */
  126. deleteReciveInfoReq() {
  127. /// loding.....
  128. showLoading(()=>{
  129. /// 参数信息
  130. const userInfo = {
  131. ReceiveInfoId: this.data.autoid,
  132. Header: protoHeader(FunCode.DelUserReceiveInfoReq)
  133. }
  134. /// 发送请求
  135. sendMsgToMQ({
  136. data: {
  137. data: JSON.stringify(userInfo),
  138. funCodeReq: FunCode.DelUserReceiveInfoReq,
  139. funCodeRsp: FunCode.DelUserReceiveInfoRsp,
  140. isEncrypted: isEncrypted()
  141. },
  142. success: (res) => {
  143. /// 操作失败
  144. if (res.code != 0) {
  145. hideLoading(()=>{}, '删除操作失败,原因:'+res.msg, 'error')
  146. return
  147. }
  148. /// 操作成功
  149. hideLoading(()=>{
  150. /// 返回上层视图
  151. wx.navigateBack()
  152. }, '删除操作成功', 'success')
  153. },
  154. fail: (emsg) => {
  155. /// 操作失败
  156. hideLoading(()=>{}, '删除操作失败,原因:'+emsg, 'error')
  157. }
  158. })
  159. }, '删除操作请求中.....')
  160. },
  161. /**
  162. * 将收货地址设为默认
  163. */
  164. receiveIsDefaultReq() {
  165. /// loding.....
  166. showLoading(()=> {
  167. /// 参数信息
  168. const data = {
  169. AutoId: this.data.autoid,
  170. UserId: userid(),
  171. Header: protoHeader(FunCode.UserReceiveIsDefaultReq)
  172. }
  173. /// 发送请求
  174. sendMsgToMQ({
  175. data: {
  176. data: JSON.stringify(data),
  177. funCodeReq: FunCode.UserReceiveIsDefaultReq,
  178. funCodeRsp: FunCode.UserReceiveIsDefaultRsp,
  179. isEncrypted: isEncrypted()
  180. },
  181. success: (res) => {
  182. /// 操作失败
  183. if (res.code != 0) {
  184. hideLoading(()=>{}, '操作失败,原因:'+res.msg, 'error')
  185. return
  186. }
  187. hideLoading(()=>{
  188. /// 返回上层视图
  189. wx.navigateBack()
  190. }, '操作成功', 'success')
  191. },
  192. fail: (emsg) => {
  193. /// 操作失败
  194. hideLoading(()=>{}, '操作失败,原因:'+emsg, 'error')
  195. }
  196. })
  197. })
  198. },
  199. /**
  200. * 业务操作
  201. */
  202. userReciveInfoReq() {
  203. /// 合规性校验
  204. if (!this.check()) { return }
  205. /// loding.....
  206. showLoading(()=> {
  207. /// 参数信息
  208. const userInfo = { ClientSerialID: timetample(),
  209. UserID: userid(),
  210. ReceiverName: this.data.username,
  211. CardTypeID: 0,
  212. CardNum: '0',
  213. PhoneNum: this.data.mobile,
  214. CountryID: 0,
  215. ProvinceID: this.data.province,
  216. CityID: this.data.city,
  217. DistrictID: this.data.country,
  218. Address: this.data.detailAddress,
  219. TakeRemark: '',
  220. ReceiveInfoId: this.data.autoid,
  221. Header: protoHeader(FunCode.UserReceiveInfoReq)
  222. }
  223. /// 发送请求
  224. sendMsgToMQ({
  225. data: {
  226. data: JSON.stringify(userInfo),
  227. funCodeReq: FunCode.UserReceiveInfoReq,
  228. funCodeRsp: FunCode.UserReceiveInfoRsp,
  229. isEncrypted: isEncrypted()
  230. },
  231. success: (res) => {
  232. /// 操作失败
  233. if (res.code != 0) {
  234. hideLoading(()=>{}, '操作失败,原因:'+res.msg, 'error')
  235. return
  236. }
  237. /// 操作失败
  238. hideLoading(()=>{
  239. /// 返回上层视图
  240. wx.navigateBack()
  241. }, '操作成功', 'success')
  242. },
  243. fail: (emsg) => {
  244. /// 操作失败
  245. hideLoading(()=>{}, '操作失败,原因:'+emsg, 'error')
  246. }
  247. })
  248. }, '操作请求中......')
  249. },
  250. /**
  251. * 生命周期函数--监听页面加载
  252. */
  253. onLoad(options: any) {
  254. /// 传参信息
  255. const d: GuangZuan.UserReceiveInfo = JSON.parse(options.id ?? '')
  256. this.setData({
  257. username: d.receivername,
  258. mobile: d.phonenum,
  259. province: d.provinceid,
  260. city: d.cityid,
  261. country: d.districtid,
  262. detailAddress: d.address,
  263. autoid: d.autoid,
  264. region: d.provincename+d.cityname+d.countryname,
  265. check: d.isdefault == 1
  266. })
  267. },
  268. /**
  269. * 生命周期函数--监听页面初次渲染完成
  270. */
  271. onReady() {},
  272. /**
  273. * 生命周期函数--监听页面显示
  274. */
  275. onShow() {},
  276. /**
  277. * 生命周期函数--监听页面隐藏
  278. */
  279. onHide() {},
  280. /**
  281. * 生命周期函数--监听页面卸载
  282. */
  283. onUnload() {
  284. },
  285. /**
  286. * 页面相关事件处理函数--监听用户下拉动作
  287. */
  288. onPullDownRefresh() {},
  289. /**
  290. * 页面上拉触底事件的处理函数
  291. */
  292. onReachBottom() {},
  293. /**
  294. * 用户点击右上角分享
  295. */
  296. onShareAppMessage() {}
  297. })