index.ts 7.7 KB

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