order-detail.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. // pages/orders/order-detail.ts
  2. import { api_executeOrder, api_executePayment, api_queryByParamName, api_userPaymentOrderDetail, api_userPaymentOrderUnpaid } from "../../api/login";
  3. import { api_sysAreaQueryAllProvince, api_userReceiveAddressPage, api_userReceiveAddressRemove, api_userReceiveAddressSave, api_userReceiveAddressUpdate } from "../../api/new";
  4. import { formatPrice, GRADE_ENUM } from "../../utils/util";
  5. // 获取应用实例
  6. const app = getApp<IAppOption>()
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. backParams: null,
  13. serviceShow: true,
  14. status: '',
  15. statusList: {
  16. ing: {
  17. logo: './images/ing.png',
  18. title: '确认订单',
  19. content: '请尽快完成支付,以便我们为您处理订单'
  20. },
  21. },
  22. goodsInfo: {} as any,
  23. hasInstrument: false, // 是否有乐器
  24. receiveAddress: '', // 选择的地址信息
  25. receiveAddressInfo: {
  26. addressDetail: '',
  27. name: '',
  28. phoneNumber: ''
  29. },
  30. userBeneficiaryId: '', // 添加购买人信息
  31. userBeneficiaryInfo: {
  32. name: '',
  33. phoneNumber: '',
  34. schoolInfo: ''
  35. },
  36. paymentType: null as any, // 支付类型
  37. paymentChannel: null as any,
  38. showService: false,
  39. areaList: [] as any,
  40. currentValues: [] as any,
  41. showDialog: false, // 删除弹窗
  42. selectAddressId: '', // 选中的编号
  43. showArea: false, // 地区
  44. addressShow: false, // 添加/修改收货地址
  45. addressListShow: false, // 收货地址列表
  46. addressList: [] as any, // 收货地址列表
  47. showAreaAfterLeave: false, // 所在地区
  48. cacheArea: [] as { cityCode: string, shiftCityCode: string }[], // 临时存储的对应关系
  49. // 添加地址表单信息
  50. id: "",
  51. name: '',
  52. phoneNumber: '',
  53. detailAddress: '',
  54. cityCode: null,
  55. cityName: "",
  56. provinceCode: 0,
  57. provinceName: "",
  58. regionCode: null,
  59. regionName: "",
  60. },
  61. /**
  62. * 生命周期函数--监听页面加载
  63. */
  64. onLoad(options: any) {
  65. this.queryPayType()
  66. this.getAddresss()
  67. this.getAreas()
  68. if (options.orderInfo) {
  69. const goods = JSON.parse(decodeURIComponent(options.orderInfo));
  70. // console.log(goods, 'goods')
  71. // console.log(options, 'options')
  72. const infos = {
  73. allSalePrice: 0,
  74. allOriginPrice: 0,
  75. allDiscountPrice: '',
  76. integerPart: '',
  77. decimalPart: '',
  78. name: '',
  79. shopId: '',
  80. orderNo: options.orderNo || '',
  81. goodsList: [] as any
  82. }
  83. // 是否有乐器
  84. let hasInstrument = false
  85. for (let i in goods) {
  86. const item = goods[i]
  87. if (item.goodsType === "INSTRUMENTS") {
  88. hasInstrument = true
  89. }
  90. infos.name = infos.name ? infos.name + '+' + item.name : item.name
  91. infos.shopId = item.shopId
  92. const afterPrice: any = formatPrice(item.salePrice)
  93. infos.goodsList.push({
  94. ...item,
  95. ...afterPrice
  96. })
  97. infos.allSalePrice += Number(item.salePrice)
  98. infos.allOriginPrice += Number(item.originalPrice)
  99. }
  100. const allAfterPrice: any = formatPrice(infos.allSalePrice)
  101. // console.log(infos.allOriginPrice, infos.allSalePrice)
  102. infos.allDiscountPrice = formatPrice(infos.allOriginPrice - infos.allSalePrice, 'ALL') as string
  103. infos.integerPart = allAfterPrice.integerPart
  104. infos.decimalPart = allAfterPrice.decimalPart
  105. // console.log(infos, 'infos')
  106. this.setData({
  107. goodsInfo: infos,
  108. status: options.status || '',
  109. hasInstrument
  110. });
  111. }
  112. this.getOrderDetail()
  113. },
  114. onShow() {
  115. if (this.data.backParams) {
  116. // console.log(this.data.backParams, 'backParams'); // { key: 'value' }
  117. const backParams: any = this.data.backParams || {};
  118. this.setData({
  119. userBeneficiaryId: backParams.userBeneficiaryId,
  120. userBeneficiaryInfo: {
  121. name: backParams.name,
  122. phoneNumber: backParams.phone,
  123. schoolInfo: backParams.schoolInfo
  124. },
  125. backParams: null // 清空参数
  126. })
  127. }
  128. this.setData({
  129. serviceShow: true
  130. })
  131. },
  132. onHide() {
  133. this.setData({
  134. serviceShow: false
  135. })
  136. },
  137. /** 获取订单详情 */
  138. async getOrderDetail() {
  139. try {
  140. if (!this.data.goodsInfo.orderNo) return
  141. const { data } = await api_userPaymentOrderDetail(this.data.goodsInfo.orderNo, {
  142. version: 'V2'
  143. });
  144. // console.log(data, 'data')
  145. const result = data.data || {}
  146. const addresses: any = result.addresses
  147. const beneficiary: any = result.beneficiary
  148. const tempSchoolAddress = [beneficiary?.provinceName, beneficiary?.cityName, beneficiary?.regionName, beneficiary?.schoolAreaName, GRADE_ENUM[beneficiary?.currentGradeNum], beneficiary?.currentClass + '班']
  149. this.setData({
  150. receiveAddress: addresses?.id,
  151. receiveAddressInfo: {
  152. addressDetail: addresses?.detailAddress,
  153. name: addresses?.name,
  154. phoneNumber: addresses?.phoneNumber
  155. },
  156. userBeneficiaryId: beneficiary.schoolAreaId, // 添加购买人信息
  157. userBeneficiaryInfo: {
  158. name: beneficiary.name,
  159. phoneNumber: beneficiary.phone,
  160. schoolInfo: tempSchoolAddress.join('')
  161. },
  162. 'goodsInfo.createTime': result.createTime
  163. })
  164. } catch {
  165. //
  166. }
  167. },
  168. /** 地址列表 */
  169. async getAddresss() {
  170. try {
  171. const { data } = await api_userReceiveAddressPage({ page: 1, rows: -1 })
  172. this.setData({
  173. addressList: data.data.rows || []
  174. })
  175. } catch {
  176. //
  177. }
  178. },
  179. /** 获取省市区 */
  180. async getAreas() {
  181. try {
  182. const { data } = await api_sysAreaQueryAllProvince({})
  183. const areaList: any = this.formateArea(data.data)
  184. const currentValues = []
  185. if (areaList?.province_list) {
  186. // 获取第一个键值对
  187. const firstKey = Object.keys(areaList?.province_list)[0];
  188. // 通过键获取值
  189. const firstValue = areaList?.province_list[firstKey];
  190. currentValues.push({
  191. code: firstKey,
  192. name: firstValue
  193. })
  194. }
  195. if (areaList?.city_list) {
  196. // 获取第一个键值对
  197. const firstKey = Object.keys(areaList?.city_list)[0];
  198. // 通过键获取值
  199. const firstValue = areaList?.city_list[firstKey];
  200. currentValues.push({
  201. code: firstKey,
  202. name: firstValue
  203. })
  204. }
  205. if (areaList?.county_list) {
  206. // 获取第一个键值对
  207. const firstKey = Object.keys(areaList?.county_list)[0];
  208. // 通过键获取值
  209. const firstValue = areaList?.county_list[firstKey];
  210. currentValues.push({
  211. code: firstKey,
  212. name: firstValue
  213. })
  214. }
  215. this.setData({
  216. areaList,
  217. currentValues
  218. })
  219. } catch {
  220. //
  221. }
  222. },
  223. formateArea(area: any[]) {
  224. const province_list: { [_: string]: string } = {};
  225. const city_list: { [_: string]: string } = {};
  226. const county_list: { [_: string]: string } = {};
  227. area.forEach((item: any) => {
  228. province_list[item.code] = item.name;
  229. });
  230. area.forEach((item: any) => {
  231. item.areas && item.areas.forEach((city: any, index: number) => {
  232. let code = city.code + ""
  233. // 某些数据不标准 这里需要转换一下
  234. if (code[4] !== "0" || code[5] !== "0") {
  235. // 现在把区域的数据改为市的
  236. const newCode = code.substring(0, 2) + (index < 10 ? `a${index}` : index < 20 ? `b${index - 10}` : index < 30 ? `c${index - 20}` : `d${index - 30}`) + "00";
  237. this.data.cacheArea.push({
  238. cityCode: code,
  239. shiftCityCode: newCode
  240. })
  241. code = newCode
  242. }
  243. city_list[code] = city.name;
  244. });
  245. });
  246. area.forEach((item: any) => {
  247. item.areas && item.areas.forEach((city: any) => {
  248. city.areas && city.areas.forEach((county: any) => {
  249. county_list[county.code] = county.name;
  250. });
  251. });
  252. });
  253. return {
  254. province_list,
  255. city_list,
  256. county_list
  257. };
  258. },
  259. // 转换
  260. formateCityCode(reverse?: boolean) {
  261. if (!this.data.regionCode && this.data.cityCode) {
  262. const cityCodeObj = this.data.cacheArea.find((item: any) => {
  263. return item[reverse ? "cityCode" : "shiftCityCode"] == this.data.cityCode
  264. })
  265. console.log(this.data.cacheArea, 'this.data.cacheArea', reverse ? "shiftCityCode" : "cityCode", cityCodeObj)
  266. return cityCodeObj ? cityCodeObj[reverse ? "shiftCityCode" : "cityCode"] : ""
  267. }
  268. return this.data.cityCode
  269. },
  270. // 获取后台配置的支付方式
  271. async queryPayType() {
  272. try {
  273. // wxlite_payment_service_provider
  274. const { data } = await api_queryByParamName({
  275. paramName: app.globalData.appId
  276. });
  277. if (data.code == 200) {
  278. const paramValue = data.data.paramValue ? JSON.parse(data.data.paramValue) : {}
  279. this.setData({
  280. paymentType: paramValue.vendor,
  281. paymentChannel: paramValue.channel
  282. });
  283. }
  284. } catch (error) {
  285. console.log(error, "error");
  286. }
  287. },
  288. onPayError(message?: string) {
  289. wx.hideLoading()
  290. wx.showToast({
  291. title: message || '支付取消',
  292. icon: 'none'
  293. })
  294. },
  295. // 购买
  296. async onSubmit() {
  297. if (!this.data.receiveAddress && this.data.hasInstrument) {
  298. wx.showToast({
  299. title: '请选择收货地址',
  300. icon: 'none'
  301. })
  302. return
  303. }
  304. if (!this.data.userBeneficiaryId) {
  305. wx.showToast({
  306. title: '请添加购买人',
  307. icon: 'none'
  308. })
  309. return
  310. }
  311. wx.showLoading({
  312. mask: true,
  313. title: "订单提交中...",
  314. });
  315. try {
  316. // const { salePrice, shopId, name, id, orderNo } = this.data.goodsInfo
  317. const { allSalePrice, shopId, name, orderNo, goodsList } = this.data.goodsInfo
  318. const goodsInfos: any = []
  319. goodsList.forEach((item: any) => {
  320. goodsInfos.push({
  321. "goodsId": item.id,
  322. "goodsNum": 1,
  323. "goodsType": item.goodsType,
  324. "paymentCashAmount": item.salePrice,
  325. "paymentCouponAmount": 0
  326. })
  327. })
  328. if (orderNo) {
  329. const { data } = await api_userPaymentOrderUnpaid({
  330. orderNo: orderNo,
  331. paymentType: 'WECHAT_MINI'
  332. })
  333. if (data.code === 200) {
  334. const { paymentConfig, paymentType, orderNo } = data.data.paymentConfig
  335. this.onExecutePay(paymentConfig, paymentType, orderNo)
  336. } else {
  337. this.onPayError()
  338. }
  339. } else {
  340. const { data } = await api_executeOrder({
  341. "orderType": "WECHAT_MINI",
  342. "paymentType": this.data.paymentType,
  343. "paymentCashAmount": allSalePrice,
  344. "paymentCouponAmount": 0,
  345. "shopId": shopId,
  346. "openId": app.globalData.userInfo?.liteOpenid,
  347. "goodsInfos": goodsInfos,
  348. receiveAddress: this.data.receiveAddress,
  349. userBeneficiaryId: this.data.userBeneficiaryId,
  350. "orderName": name,
  351. "orderDesc": name
  352. })
  353. if (data.code === 200) {
  354. const { paymentConfig, paymentType, orderNo } = data.data
  355. this.onExecutePay(paymentConfig, paymentType, orderNo)
  356. } else if (data.code === 5200) {
  357. wx.hideLoading()
  358. wx.showToast({
  359. title: data.message,
  360. icon: 'none'
  361. })
  362. } else if([5435, 5436, 5437, 5439, 5442, 5443, 5408, 5427, 5432].includes(data.code)) {
  363. wx.hideLoading()
  364. wx.showToast({
  365. title: data.message,
  366. icon: 'none'
  367. })
  368. setTimeout(() => {
  369. wx.navigateBack()
  370. }, 1000)
  371. } else {
  372. this.onPayError()
  373. }
  374. }
  375. } catch(e) {
  376. wx.hideLoading()
  377. }
  378. },
  379. async onExecutePay(paymentConfig: any, paymentType: string, orderNo: string) {
  380. wx.login({
  381. success: async (wxres: any) => {
  382. const res = await api_executePayment({
  383. merOrderNo: paymentConfig.merOrderNo,
  384. paymentChannel: this.data.paymentChannel || 'wx_lite',
  385. paymentType,
  386. userId: app.globalData.userInfo?.id,
  387. code: wxres.code,
  388. wxMiniAppId: app.globalData.appId
  389. })
  390. wx.hideLoading()
  391. if (res.data.code === 200) {
  392. this.onPay(paymentType, res.data.data.reqParams, orderNo)
  393. } else if([5435, 5436, 5437, 5439, 5442, 5443, 5408, 5427, 5432].includes(res.data.code)) {
  394. wx.hideLoading()
  395. wx.showToast({
  396. title: res.data.message,
  397. icon: 'none'
  398. })
  399. setTimeout(() => {
  400. wx.navigateBack()
  401. }, 1000)
  402. } else {
  403. this.onPayError(res.data.message)
  404. }
  405. },
  406. fail: () => {
  407. this.onPayError()
  408. }
  409. })
  410. },
  411. onPay(paymentType: string, paymentConfig: any, orderNo: string) {
  412. const isYeePay = paymentType.indexOf('yeepay') !== -1
  413. const prePayInfo = isYeePay ? JSON.parse(paymentConfig.prePayTn)
  414. : paymentConfig?.expend
  415. ? JSON.parse(paymentConfig?.expend?.pay_info)
  416. : paymentConfig
  417. const that = this
  418. wx.requestPayment({
  419. timeStamp: prePayInfo.timeStamp,
  420. nonceStr: prePayInfo.nonceStr,
  421. package: prePayInfo.package ? prePayInfo.package : prePayInfo.packageValue,
  422. paySign: prePayInfo.paySign,
  423. signType: prePayInfo.signType ? prePayInfo.signType : 'MD5',
  424. success() {
  425. wx.showToast({ title: '支付成功', icon: 'success' });
  426. wx.redirectTo({
  427. url: '/pages/orders/order-result?orderNo=' + orderNo
  428. })
  429. },
  430. fail(ressonInfo) {
  431. console.log('支付失败', ressonInfo)
  432. that.onPayError()
  433. const goodsInfo = that.data.goodsInfo
  434. goodsInfo.orderNo = orderNo
  435. that.setData({
  436. goodsInfo
  437. })
  438. }
  439. })
  440. },
  441. /** 客服 */
  442. onService() {
  443. // console.log("showService")
  444. this.setData({
  445. showService: true
  446. })
  447. },
  448. changePop(event: { detail: any }) {
  449. this.setData({
  450. showService: event.detail
  451. })
  452. },
  453. /** 选择收货地址 */
  454. onTagAddress() {
  455. if(this.data.goodsInfo.orderNo) return
  456. if (this.data.addressList.length > 0) {
  457. this.onShowAddressList()
  458. } else {
  459. this.onShowAddress()
  460. }
  461. },
  462. /** 显示添加/修改地址 */
  463. onShowAddress() {
  464. this.setData({
  465. addressShow: true
  466. })
  467. },
  468. /** 关闭添加/修改地址 */
  469. onCloseAddress() {
  470. this.setData({
  471. addressShow: false
  472. })
  473. },
  474. onAddressAfterLeave() {
  475. this.setData({
  476. id: "",
  477. name: '',
  478. phoneNumber: '',
  479. detailAddress: '',
  480. cityCode: 0,
  481. cityName: "",
  482. provinceCode: 0,
  483. provinceName: "",
  484. regionCode: null,
  485. regionName: "",
  486. })
  487. },
  488. /** 显示收货地址 */
  489. onShowAddressList() {
  490. this.setData({
  491. addressListShow: true
  492. })
  493. },
  494. /** 关闭收货地址 */
  495. onCloseAddressList() {
  496. this.setData({
  497. addressListShow: false
  498. })
  499. },
  500. /** 添加购买人 */
  501. onAddBuyer() {
  502. wx.navigateTo({
  503. url: "../buyerInformation/index?userBeneficiaryId=" + this.data.userBeneficiaryId,
  504. });
  505. },
  506. /** 显示选择地区 */
  507. onShowAreaList() {
  508. this.setData({
  509. showArea: true
  510. })
  511. },
  512. /** 关闭选择地区 */
  513. onCloseAreaList() {
  514. this.setData({
  515. showArea: false
  516. })
  517. },
  518. onAreaBeforeEnter() {
  519. this.setData({
  520. showAreaAfterLeave: false
  521. })
  522. },
  523. onAreaAfterLeave() {
  524. this.setData({
  525. showAreaAfterLeave: true
  526. })
  527. },
  528. /** 确定选择地区 */
  529. submitArea() {
  530. const selectedOptions = this.data.currentValues
  531. this.setData({
  532. provinceCode: selectedOptions[0].code,
  533. cityCode: selectedOptions[1].code,
  534. regionCode: selectedOptions[2]?.code || null,
  535. provinceName: selectedOptions[0].name || '',
  536. cityName: selectedOptions[1].name || '',
  537. regionName: selectedOptions[2]?.name || '',
  538. showArea: false
  539. })
  540. },
  541. onCopy(e: { currentTarget: any }) {
  542. wx.setClipboardData({
  543. data: e.currentTarget.dataset.orderno,
  544. success: () => {
  545. wx.showToast({ title: '复制成功', icon: 'none' })
  546. },
  547. fail: () => {
  548. wx.showToast({ title: '复制失败,请稍后再试', icon: 'none' })
  549. }
  550. })
  551. },
  552. // cancelArea() {
  553. // this.setData({ showArea: false })
  554. // },
  555. // confirmArea(event: any) {
  556. // console.log(event)
  557. // // const selectedOptions = event.detail.values
  558. // const selectedOptions = this.data.currentValues
  559. // this.setData({
  560. // provinceCode: selectedOptions[0].code,
  561. // cityCode: selectedOptions[1].code,
  562. // regionCode: selectedOptions[2].code,
  563. // provinceName: selectedOptions[0].name,
  564. // cityName: selectedOptions[1].name,
  565. // regionName: selectedOptions[2].name,
  566. // showArea: false,
  567. // areaComponent: null as any
  568. // })
  569. // // forms.provinceCode = selectedOptions[0].value;
  570. // // forms.cityCode = selectedOptions[1].value;
  571. // // forms.regionCode = selectedOptions[2].value;
  572. // // data.cityName = selectedOptions
  573. // // .map((item: any) => item.text)
  574. // // .join('-');
  575. // // data.showArea = false;
  576. // // }}
  577. // },
  578. changeArea(e: any) {
  579. this.setData({
  580. currentValues: e.detail.values
  581. })
  582. },
  583. /** 创建/修改收货地址 */
  584. async onOperationAddress() {
  585. const addressForm = this.data
  586. try {
  587. if (!addressForm.name) {
  588. wx.showToast({
  589. title: '请输入收货人姓名',
  590. icon: "none"
  591. })
  592. return
  593. }
  594. if (!addressForm.phoneNumber || !/^1[3456789]\d{9}$/.test(addressForm.phoneNumber)) {
  595. wx.showToast({
  596. title: '请输入正确的手机号',
  597. icon: "none"
  598. })
  599. return
  600. }
  601. if (!addressForm.provinceCode || !addressForm.cityCode) {
  602. wx.showToast({
  603. title: '请选择地区',
  604. icon: "none"
  605. })
  606. return
  607. }
  608. if (!addressForm.detailAddress) {
  609. wx.showToast({
  610. title: '请输入详细地址',
  611. icon: "none"
  612. })
  613. return
  614. }
  615. if (addressForm.id) {
  616. const citycode = this.formateCityCode()
  617. await api_userReceiveAddressUpdate({
  618. id: addressForm.id,
  619. name: addressForm.name,
  620. phoneNumber: addressForm.phoneNumber,
  621. province: addressForm.provinceCode,
  622. city: citycode,
  623. region: addressForm.regionCode || '',
  624. detailAddress: addressForm.detailAddress
  625. })
  626. this.getAddresss()
  627. this.onCloseAddress()
  628. } else {
  629. const citycode = this.formateCityCode()
  630. const { data } = await api_userReceiveAddressSave({
  631. name: addressForm.name,
  632. phoneNumber: addressForm.phoneNumber,
  633. province: addressForm.provinceCode,
  634. city: citycode,
  635. region: addressForm.regionCode || '',
  636. detailAddress: addressForm.detailAddress
  637. })
  638. this.setData({
  639. receiveAddress: this.data.receiveAddress || data.data,
  640. 'receiveAddressInfo.addressDetail': addressForm.provinceName + addressForm.cityName + addressForm.regionName + addressForm.detailAddress,
  641. 'receiveAddressInfo.name': addressForm.name,
  642. 'receiveAddressInfo.phoneNumber': addressForm.phoneNumber
  643. })
  644. this.getAddresss()
  645. this.onCloseAddress()
  646. }
  647. } catch {
  648. //
  649. }
  650. },
  651. /** 选择地址 */
  652. onSelectAddress(e: any) {
  653. const id = e.currentTarget.dataset.id
  654. const addressInfo = this.data.addressList.find((item: any) => item.id === id)
  655. this.setData({
  656. receiveAddress: addressInfo.id,
  657. 'receiveAddressInfo.addressDetail': addressInfo.provinceName + addressInfo.cityName + addressInfo.regionName + addressInfo.detailAddress,
  658. 'receiveAddressInfo.name': addressInfo.name,
  659. 'receiveAddressInfo.phoneNumber': addressInfo.phoneNumber,
  660. addressListShow: false
  661. })
  662. },
  663. /** Dialog 确定 */
  664. async onDialogConfirm() {
  665. try {
  666. await api_userReceiveAddressRemove({
  667. id: this.data.selectAddressId
  668. })
  669. this.getAddresss()
  670. // 如果删除的是已经选中的地址,则需要重置数据
  671. if (this.data.selectAddressId === this.data.receiveAddress) {
  672. this.setData({
  673. selectAddressId: '',
  674. receiveAddress: '',
  675. 'receiveAddressInfo.name': '',
  676. 'receiveAddressInfo.phoneNumber': '',
  677. 'receiveAddressInfo.addressDetail': ''
  678. })
  679. }
  680. this.onDialogClose()
  681. } catch {
  682. }
  683. },
  684. /** Dialog 隐藏 */
  685. onDialogClose() {
  686. this.setData({
  687. showDialog: false
  688. })
  689. },
  690. /** 删除地址 */
  691. onRemoveAddress(e: any) {
  692. this.setData({
  693. showDialog: true,
  694. selectAddressId: e.target.dataset.id
  695. })
  696. },
  697. /** 修改地址 */
  698. onUpdateAddress(e: any) {
  699. const id = e.target.dataset.id
  700. const addressInfo = this.data.addressList.find((item: any) => item.id === id)
  701. this.setData({
  702. addressShow: true,
  703. id: addressInfo.id,
  704. name: addressInfo.name,
  705. phoneNumber: addressInfo.phoneNumber,
  706. detailAddress: addressInfo.detailAddress,
  707. cityCode: addressInfo.city,
  708. cityName: addressInfo.cityName,
  709. provinceCode: addressInfo.province,
  710. provinceName: addressInfo.provinceName,
  711. regionCode: addressInfo.region,
  712. regionName: addressInfo.regionName,
  713. }, () => {
  714. const cityCode: any = this.formateCityCode(true)
  715. this.setData({
  716. cityCode
  717. })
  718. })
  719. },
  720. /**
  721. * 生命周期函数--监听页面初次渲染完成
  722. */
  723. onReady() {
  724. },
  725. /**
  726. * 生命周期函数--监听页面卸载
  727. */
  728. onUnload() {
  729. },
  730. /**
  731. * 页面相关事件处理函数--监听用户下拉动作
  732. */
  733. onPullDownRefresh() {
  734. },
  735. /**
  736. * 页面上拉触底事件的处理函数
  737. */
  738. onReachBottom() {
  739. },
  740. /**
  741. * 用户点击右上角分享
  742. */
  743. onShareAppMessage() {
  744. return {
  745. title: '音乐数字AI',
  746. path: '/pages/index/index',
  747. imageUrl: 'https://oss.dayaedu.com/ktyq/1733309357691.png'
  748. }
  749. }
  750. })