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