order-detail.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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. that.getOrderDetail()
  439. }
  440. })
  441. },
  442. /** 客服 */
  443. onService() {
  444. // console.log("showService")
  445. this.setData({
  446. showService: true
  447. })
  448. },
  449. changePop(event: { detail: any }) {
  450. this.setData({
  451. showService: event.detail
  452. })
  453. },
  454. /** 选择收货地址 */
  455. onTagAddress() {
  456. if(this.data.goodsInfo.orderNo) return
  457. if (this.data.addressList.length > 0) {
  458. this.onShowAddressList()
  459. } else {
  460. this.onShowAddress()
  461. }
  462. },
  463. /** 显示添加/修改地址 */
  464. onShowAddress() {
  465. this.setData({
  466. addressShow: true
  467. })
  468. },
  469. /** 关闭添加/修改地址 */
  470. onCloseAddress() {
  471. this.setData({
  472. addressShow: false
  473. })
  474. },
  475. onAddressAfterLeave() {
  476. this.setData({
  477. id: "",
  478. name: '',
  479. phoneNumber: '',
  480. detailAddress: '',
  481. cityCode: null,
  482. cityName: "",
  483. provinceCode: 0,
  484. provinceName: "",
  485. regionCode: null,
  486. regionName: "",
  487. })
  488. },
  489. /** 显示收货地址 */
  490. onShowAddressList() {
  491. this.setData({
  492. addressListShow: true
  493. })
  494. },
  495. /** 关闭收货地址 */
  496. onCloseAddressList() {
  497. this.setData({
  498. addressListShow: false
  499. })
  500. },
  501. /** 添加购买人 */
  502. onAddBuyer() {
  503. wx.navigateTo({
  504. url: "../buyerInformation/index?userBeneficiaryId=" + this.data.userBeneficiaryId,
  505. });
  506. },
  507. /** 显示选择地区 */
  508. onShowAreaList() {
  509. this.setData({
  510. showArea: true
  511. })
  512. },
  513. /** 关闭选择地区 */
  514. onCloseAreaList() {
  515. this.setData({
  516. showArea: false
  517. })
  518. },
  519. onAreaBeforeEnter() {
  520. this.setData({
  521. showAreaAfterLeave: false
  522. })
  523. },
  524. onAreaAfterLeave() {
  525. this.setData({
  526. showAreaAfterLeave: true
  527. })
  528. },
  529. /** 确定选择地区 */
  530. submitArea() {
  531. const selectedOptions = this.data.currentValues
  532. this.setData({
  533. provinceCode: selectedOptions[0].code,
  534. cityCode: selectedOptions[1].code,
  535. regionCode: selectedOptions[2]?.code || null,
  536. provinceName: selectedOptions[0].name || '',
  537. cityName: selectedOptions[1].name || '',
  538. regionName: selectedOptions[2]?.name || '',
  539. showArea: false
  540. })
  541. },
  542. onCopy(e: { currentTarget: any }) {
  543. wx.setClipboardData({
  544. data: e.currentTarget.dataset.orderno,
  545. success: () => {
  546. wx.showToast({ title: '复制成功', icon: 'none' })
  547. },
  548. fail: () => {
  549. wx.showToast({ title: '复制失败,请稍后再试', icon: 'none' })
  550. }
  551. })
  552. },
  553. // cancelArea() {
  554. // this.setData({ showArea: false })
  555. // },
  556. // confirmArea(event: any) {
  557. // console.log(event)
  558. // // const selectedOptions = event.detail.values
  559. // const selectedOptions = this.data.currentValues
  560. // this.setData({
  561. // provinceCode: selectedOptions[0].code,
  562. // cityCode: selectedOptions[1].code,
  563. // regionCode: selectedOptions[2].code,
  564. // provinceName: selectedOptions[0].name,
  565. // cityName: selectedOptions[1].name,
  566. // regionName: selectedOptions[2].name,
  567. // showArea: false,
  568. // areaComponent: null as any
  569. // })
  570. // // forms.provinceCode = selectedOptions[0].value;
  571. // // forms.cityCode = selectedOptions[1].value;
  572. // // forms.regionCode = selectedOptions[2].value;
  573. // // data.cityName = selectedOptions
  574. // // .map((item: any) => item.text)
  575. // // .join('-');
  576. // // data.showArea = false;
  577. // // }}
  578. // },
  579. changeArea(e: any) {
  580. this.setData({
  581. currentValues: e.detail.values
  582. })
  583. },
  584. /** 创建/修改收货地址 */
  585. async onOperationAddress() {
  586. const addressForm = this.data
  587. try {
  588. if (!addressForm.name) {
  589. wx.showToast({
  590. title: '请输入收货人姓名',
  591. icon: "none"
  592. })
  593. return
  594. }
  595. if (!addressForm.phoneNumber || !/^1[3456789]\d{9}$/.test(addressForm.phoneNumber)) {
  596. wx.showToast({
  597. title: '请输入正确的手机号',
  598. icon: "none"
  599. })
  600. return
  601. }
  602. if (!addressForm.provinceCode || !addressForm.cityCode) {
  603. wx.showToast({
  604. title: '请选择地区',
  605. icon: "none"
  606. })
  607. return
  608. }
  609. if (!addressForm.detailAddress) {
  610. wx.showToast({
  611. title: '请输入详细地址',
  612. icon: "none"
  613. })
  614. return
  615. }
  616. if (addressForm.id) {
  617. const citycode = this.formateCityCode()
  618. await api_userReceiveAddressUpdate({
  619. id: addressForm.id,
  620. name: addressForm.name,
  621. phoneNumber: addressForm.phoneNumber,
  622. province: addressForm.provinceCode,
  623. city: citycode,
  624. region: addressForm.regionCode || '',
  625. detailAddress: addressForm.detailAddress
  626. })
  627. this.setData({
  628. 'receiveAddressInfo.addressDetail': (addressForm.provinceName || '') + (addressForm.cityName || '') + (addressForm.regionName || '') + addressForm.detailAddress,
  629. 'receiveAddressInfo.name': addressForm.name,
  630. 'receiveAddressInfo.phoneNumber': addressForm.phoneNumber
  631. })
  632. this.getAddresss()
  633. this.onCloseAddress()
  634. } else {
  635. const citycode = this.formateCityCode()
  636. const { data } = await api_userReceiveAddressSave({
  637. name: addressForm.name,
  638. phoneNumber: addressForm.phoneNumber,
  639. province: addressForm.provinceCode,
  640. city: citycode,
  641. region: addressForm.regionCode || '',
  642. detailAddress: addressForm.detailAddress
  643. })
  644. this.setData({
  645. receiveAddress: data.data,
  646. 'receiveAddressInfo.addressDetail': (addressForm.provinceName || '') + (addressForm.cityName || '') + (addressForm.regionName || '') + addressForm.detailAddress,
  647. 'receiveAddressInfo.name': addressForm.name,
  648. 'receiveAddressInfo.phoneNumber': addressForm.phoneNumber
  649. })
  650. this.getAddresss()
  651. this.onCloseAddress()
  652. }
  653. } catch {
  654. //
  655. }
  656. },
  657. /** 选择地址 */
  658. onSelectAddress(e: any) {
  659. const id = e.currentTarget.dataset.id
  660. const addressInfo = this.data.addressList.find((item: any) => item.id === id)
  661. this.setData({
  662. receiveAddress: addressInfo.id,
  663. 'receiveAddressInfo.addressDetail': addressInfo.provinceName + addressInfo.cityName + addressInfo.regionName + addressInfo.detailAddress,
  664. 'receiveAddressInfo.name': addressInfo.name,
  665. 'receiveAddressInfo.phoneNumber': addressInfo.phoneNumber,
  666. addressListShow: false
  667. })
  668. },
  669. /** Dialog 确定 */
  670. async onDialogConfirm() {
  671. try {
  672. await api_userReceiveAddressRemove({
  673. id: this.data.selectAddressId
  674. })
  675. this.getAddresss()
  676. // 如果删除的是已经选中的地址,则需要重置数据
  677. if (this.data.selectAddressId === this.data.receiveAddress) {
  678. this.setData({
  679. selectAddressId: '',
  680. receiveAddress: '',
  681. 'receiveAddressInfo.name': '',
  682. 'receiveAddressInfo.phoneNumber': '',
  683. 'receiveAddressInfo.addressDetail': ''
  684. })
  685. }
  686. this.onDialogClose()
  687. } catch {
  688. }
  689. },
  690. /** Dialog 隐藏 */
  691. onDialogClose() {
  692. this.setData({
  693. showDialog: false
  694. })
  695. },
  696. /** 删除地址 */
  697. onRemoveAddress(e: any) {
  698. this.setData({
  699. showDialog: true,
  700. selectAddressId: e.target.dataset.id
  701. })
  702. },
  703. /** 修改地址 */
  704. onUpdateAddress(e: any) {
  705. const id = e.target.dataset.id
  706. const addressInfo = this.data.addressList.find((item: any) => item.id === id)
  707. this.setData({
  708. addressShow: true,
  709. id: addressInfo.id,
  710. name: addressInfo.name,
  711. phoneNumber: addressInfo.phoneNumber,
  712. detailAddress: addressInfo.detailAddress,
  713. cityCode: addressInfo.city,
  714. cityName: addressInfo.cityName,
  715. provinceCode: addressInfo.province,
  716. provinceName: addressInfo.provinceName,
  717. regionCode: addressInfo.region,
  718. regionName: addressInfo.regionName,
  719. }, () => {
  720. const cityCode: any = this.formateCityCode(true)
  721. this.setData({
  722. cityCode
  723. })
  724. })
  725. },
  726. /**
  727. * 生命周期函数--监听页面初次渲染完成
  728. */
  729. onReady() {
  730. },
  731. /**
  732. * 生命周期函数--监听页面卸载
  733. */
  734. onUnload() {
  735. },
  736. /**
  737. * 页面相关事件处理函数--监听用户下拉动作
  738. */
  739. onPullDownRefresh() {
  740. },
  741. /**
  742. * 页面上拉触底事件的处理函数
  743. */
  744. onReachBottom() {
  745. },
  746. /**
  747. * 用户点击右上角分享
  748. */
  749. onShareAppMessage() {
  750. return {
  751. title: '音乐数字AI',
  752. path: '/pages/index/index',
  753. imageUrl: 'https://oss.dayaedu.com/ktyq/1733309357691.png'
  754. }
  755. }
  756. })