editaddress.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view style="margin-top: 160rpx;"></view>
  6. <view>
  7. <!-- 修改个人信息完善 -->
  8. <view style="margin: 0 20rpx;">
  9. <uni-forms :rules="rules" :modelValue="formData" ref="form" validate-trigger="bind"
  10. err-show-type="undertext">
  11. <uni-forms-item name="name" required label="姓名">
  12. <uni-easyinput type="text" :inputBorder="true" v-model="formData.receiver_name" placeholder="请输入收件人">
  13. </uni-easyinput>
  14. </uni-forms-item>
  15. <uni-forms-item name="phone" required label="电话">
  16. <uni-easyinput type="number" maxlength="11" :inputBorder="true" v-model="formData.phone_number"
  17. placeholder="请输入联系电话">
  18. </uni-easyinput>
  19. </uni-forms-item>
  20. <uni-forms-item name="region_code" required label="地区">
  21. <picker class="picker" mode="multiSelector" :range="region" range-key="name"
  22. :value="regionIndex" @change="pickerChange" @columnchange="pickerColumnchange">
  23. <view class="pbox" :class="{'pbox_hover':regionStr != '请选择省市区'}">
  24. <view>{{regionStr}}</view>
  25. <text class="iconfont icon-you"></text>
  26. </view>
  27. </picker>
  28. </uni-forms-item>
  29. <uni-forms-item name="detail_addr" required label="详细地址">
  30. <uni-easyinput type="text" :inputBorder="true" v-model="formData.detail_addr"
  31. placeholder="请输入详细地址(省/市/县/镇/)">
  32. </uni-easyinput>
  33. </uni-forms-item>
  34. </uni-group>
  35. </uni-forms>
  36. <button class="btn1" @click="submitForm('form')">保存</button>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import region from '@/components/pca-code.json';
  43. import mvBar from "@/components/mys_navBar/mysNavBar";
  44. export default {
  45. components: {
  46. mvBar,
  47. },
  48. data() {
  49. return {
  50. taskId: '',
  51. // 地区原数组
  52. oldRegion: region,
  53. // 处理后的数组
  54. region: [
  55. [],
  56. [],
  57. []
  58. ],
  59. // 选择省市区的下标Index 传则默认选中传递的
  60. regionIndex: [0, 0, 0],
  61. regionStr: '请选择省市区',
  62. mysNavConfig: {
  63. /* 开启单页显示首页图标 */
  64. isHome: true,
  65. /* 固定导航 */
  66. navFixed: true,
  67. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  68. navTitle: {
  69. text: "编辑收货地址",
  70. color: "",
  71. fontSize: "32rpx", // px upx rpx
  72. fontWeight: "normal", // 100 - 700
  73. },
  74. btnType: "type2",
  75. onLeftClick: '',
  76. /* type2 按钮 */
  77. type2Config: {
  78. // 左图标
  79. leftPath: "/static/img/png2.png",
  80. // 右图标
  81. rightPath: "/static/img/png4.png",
  82. // 圆角
  83. radius: "40rpx",
  84. },
  85. },
  86. formData: {
  87. receiver_name: '',
  88. phone_number: '',
  89. detail_addr: '',
  90. region_code: '',
  91. setdefault: false,
  92. },
  93. index: 0,
  94. index1: 0,
  95. data: {},
  96. show: false,
  97. rules: {
  98. detail_addr: {
  99. rules: [{
  100. required: true,
  101. errorMessage: '请输入详细地址'
  102. }, ]
  103. },
  104. name: {
  105. rules: [{
  106. required: true,
  107. errorMessage: '请输入收件人'
  108. }, ]
  109. },
  110. phone: {
  111. rules: [{
  112. required: true,
  113. errorMessage: '请输入联系电话',
  114. }, ]
  115. },
  116. region_code: {
  117. rules: [{
  118. required: true,
  119. errorMessage: '请选择所在地区'
  120. }, ]
  121. },
  122. },
  123. address_id: '',
  124. };
  125. },
  126. onLoad() {
  127. uni.showLoading()
  128. setTimeout(() => {
  129. uni.hideLoading()
  130. }, 500)
  131. },
  132. onReady() {
  133. this.initRegion()
  134. this.$refs.form.setRules(this.rules)
  135. },
  136. onLoad(options) {
  137. let data = options.textObj.replace(/""/g, "");
  138. data = JSON.parse(decodeURIComponent(data))
  139. this.formData = data.address
  140. this.taskId = data.taskId
  141. let a = this.formData.region_code.toString().slice(0, 2)
  142. let b = this.formData.region_code.toString().slice(0, 4)
  143. let c = 0
  144. for (var i = 0; i < region.length; i++) {
  145. if (region[i].code == a) {
  146. a = region[i].name
  147. for (var j = 0; j < region[i].children.length; j++) {
  148. if (region[i].children[j].code == b) {
  149. b = region[i].children[j].name
  150. for (var o = 0; o < region[i].children[j].children.length; o++) {
  151. if (region[i].children[j].children[o].code == this.formData.region_code) {
  152. c = region[i].children[j].children[o].name
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. this.regionStr = a + ' ' + b + ' ' + c
  160. },
  161. methods: {
  162. initRegion() {
  163. // 声明城市数组
  164. let cityArr = [];
  165. let countyArr = [];
  166. // 设置下标
  167. this.regionIndex = [0, 0, 0];
  168. // 改变城市列表
  169. this.region[1] = this.oldRegion[0].children.map(item => {
  170. cityArr.push({
  171. name: item.name,
  172. code: item.code
  173. });
  174. })
  175. this.$set(this.region, 1, cityArr);
  176. // 改变县区列表
  177. this.oldRegion[0].children[0].children.map(item => {
  178. countyArr.push({
  179. name: item.name,
  180. code: item.code
  181. });
  182. })
  183. this.$set(this.region, 2, countyArr);
  184. },
  185. /**
  186. * 手动提交
  187. * @param {Object} form
  188. */
  189. submitForm(form) {
  190. // console.log(this.formData);
  191. this.$refs.form.validate().then(res => {
  192. const iphoneReg1 = /^1[0-9]{10}$/
  193. if (!iphoneReg1.test(this.formData.phone_number)) {
  194. uni.showToast({
  195. title: '电话号码格式不正确',
  196. icon: 'none'
  197. })
  198. return
  199. }
  200. uni.showToast({
  201. title: '提交成功'
  202. })
  203. this.$https.post('/youngee/c/t/p/update-logistics-address', {
  204. task_id: this.taskId,
  205. region_code: this.formData.region_code,
  206. detail_addr: this.formData.detail_addr,
  207. phone_number: this.formData.phone_number,
  208. receiver_name: this.formData.receiver_name,
  209. })
  210. .then(res => {
  211. console.log(res)
  212. uni.navigateBack()
  213. })
  214. }).catch(err => {
  215. console.error('验证失败:', errors)
  216. uni.showToast({
  217. title: '请填写所有信息',
  218. icon: 'none'
  219. })
  220. })
  221. },
  222. //城市选择
  223. pickerChange(e) {
  224. // console.log(e, '1');
  225. console.log("pickerChange e.detail.value: ", e.detail.value)
  226. this.regionIndex = e.detail.value;
  227. this.regionStr = this.region[0][this.regionIndex[0]].name + ' ' + this.region[1][this.regionIndex[1]]
  228. .name + ' ' +
  229. this.region[2][this.regionIndex[2]].name;
  230. // 组件传值
  231. this.$emit('region', [this.region[0][this.regionIndex[0]].code, this.region[1][this.regionIndex[1]].code,
  232. this.region[
  233. 2][this.regionIndex[2]].code
  234. ]);
  235. this.formData.region_code = this.region[2][this.regionIndex[2]].code;
  236. console.log(this.formData.region_code)
  237. },
  238. pickerColumnchange(e) {
  239. if (e.detail.column === 0) {
  240. // 声明城市数组
  241. let cityArr = [];
  242. let countyArr = [];
  243. // 设置下标
  244. this.regionIndex = [e.detail.value, 0, 0];
  245. // 改变城市列表
  246. this.region[1] = this.oldRegion[e.detail.value].children.map(item => {
  247. cityArr.push({
  248. name: item.name,
  249. code: item.code
  250. });
  251. })
  252. this.$set(this.region, 1, cityArr);
  253. // 改变县区列表
  254. this.oldRegion[e.detail.value].children[0].children.map(item => {
  255. countyArr.push({
  256. name: item.name,
  257. code: item.code
  258. });
  259. })
  260. this.$set(this.region, 2, countyArr);
  261. }
  262. if (e.detail.column === 1) {
  263. this.regionIndex[1] = e.detail.value;
  264. this.regionIndex[2] = 0;
  265. let countyArr = [];
  266. this.oldRegion[this.regionIndex[0]].children[this.regionIndex[1]].children.map(item => {
  267. countyArr.push({
  268. name: item.name,
  269. code: item.code
  270. });
  271. })
  272. this.$set(this.region, 2, countyArr);
  273. }
  274. if (e.detail.column === 2) {
  275. this.regionIndex[2] = e.detail.value;
  276. }
  277. }
  278. },
  279. created() {
  280. let provinceArr = [];
  281. let cityArr = [];
  282. this.oldRegion.map((item, index) => {
  283. this.region[0].push({
  284. name: item.name,
  285. code: item.code
  286. });
  287. if (this.previnceId == item.code) {
  288. provinceArr = item.children;
  289. this.regionIndex[0] = index;
  290. }
  291. })
  292. // console.log(provinceArr);
  293. provinceArr.map((item, index) => {
  294. this.region[1].push({
  295. name: item.name,
  296. code: item.code
  297. });
  298. if (this.cityId == item.code) {
  299. cityArr = item.children;
  300. this.regionIndex[1] = index;
  301. }
  302. })
  303. cityArr.map((item, index) => {
  304. this.region[2].push({
  305. name: item.name,
  306. code: item.code
  307. });
  308. if (this.countyId == item.code)
  309. this.regionIndex[2] = index;
  310. })
  311. if (this.isRevise)
  312. this.regionStr = this.region[0][this.regionIndex[0]].name + ' ' + this.region[1][this.regionIndex[1]]
  313. .name + ' ' + this.region[2][this.regionIndex[2]].name;
  314. else
  315. this.regionStr = '请选择省市区';
  316. }
  317. };
  318. </script>
  319. <style>
  320. picker {
  321. position: relative;
  322. display: block;
  323. cursor: pointer;
  324. padding-left: 20rpx !important;
  325. padding-top: 14rpx !important;
  326. color: grey !important;
  327. }
  328. /deep/.uni-forms-item__inner {
  329. border-bottom: none !important;
  330. margin-bottom: 0 !important;
  331. }
  332. </style>
  333. <style lang="scss" scoped>
  334. @charset "UTF-8";
  335. /* 头条小程序组件内不能引入字体 */
  336. /* #ifdef MP-TOUTIAO */
  337. @font-face {
  338. font-family: uniicons;
  339. font-weight: normal;
  340. font-style: normal;
  341. src: url("~@/static/uni.ttf") format("truetype");
  342. }
  343. /* #endif */
  344. /* #ifndef APP-NVUE */
  345. page {
  346. display: flex;
  347. flex-direction: column;
  348. box-sizing: border-box;
  349. background-color: #FFFFFF;
  350. min-height: 100%;
  351. height: auto;
  352. }
  353. view {
  354. font-size: 14px;
  355. line-height: inherit;
  356. }
  357. .menu {
  358. position: fixed;
  359. top: 180rpx;
  360. background-color: #FFFFFF;
  361. justify-content: space-around;
  362. height: 5%;
  363. width: 100%;
  364. display: flex;
  365. z-index: 10;
  366. margin-bottom: 10rpx;
  367. }
  368. .menu-item p {
  369. font-weight: 600;
  370. font-size: 90%;
  371. &.lor {
  372. border-bottom: 5rpx solid #F0D232;
  373. color: #F0D232;
  374. padding-bottom: 15rpx;
  375. }
  376. }
  377. .setdeault {
  378. display: flex;
  379. justify-content: space-between;
  380. }
  381. .btn1 {
  382. margin: 30rpx;
  383. font-size: 35rpx;
  384. color: #000;
  385. background-color: #F0D232;
  386. border: none;
  387. border-radius: 0;
  388. }
  389. .example {
  390. padding: 0 15px 15px;
  391. }
  392. .example-info {
  393. padding: 15px;
  394. color: #3b4144;
  395. background: #ffffff;
  396. }
  397. .example-body {
  398. /* #ifndef APP-NVUE */
  399. display: flex;
  400. /* #endif */
  401. flex-direction: row;
  402. flex-wrap: wrap;
  403. justify-content: center;
  404. padding: 0;
  405. font-size: 14px;
  406. background-color: #ffffff;
  407. }
  408. /* #endif */
  409. .example {
  410. padding: 0 15px;
  411. }
  412. .example-info {
  413. /* #ifndef APP-NVUE */
  414. display: block;
  415. /* #endif */
  416. padding: 15px;
  417. color: #3b4144;
  418. background-color: #ffffff;
  419. font-size: 14px;
  420. line-height: 20px;
  421. }
  422. .example-info-text {
  423. font-size: 14px;
  424. line-height: 20px;
  425. color: #3b4144;
  426. }
  427. .example-body {
  428. flex-direction: column;
  429. padding: 15px;
  430. background-color: #ffffff;
  431. }
  432. .word-btn-white {
  433. font-size: 18px;
  434. color: #FFFFFF;
  435. }
  436. .word-btn {
  437. /* #ifndef APP-NVUE */
  438. display: flex;
  439. /* #endif */
  440. flex-direction: row;
  441. align-items: center;
  442. justify-content: center;
  443. border-radius: 6px;
  444. height: 48px;
  445. margin: 15px;
  446. background-color: #007AFF;
  447. }
  448. .word-btn--hover {
  449. background-color: #4ca2ff;
  450. }
  451. .example {
  452. padding: 0 10px 10px;
  453. }
  454. .uni-input-border,
  455. .uni-textarea-border {
  456. flex: 1;
  457. font-size: 14px;
  458. color: #666;
  459. border: 1px #FFFFFF solid;
  460. border-radius: 5px;
  461. /* #ifndef APP-NVUE */
  462. box-sizing: border-box;
  463. /* #endif */
  464. }
  465. .uni-input-border {
  466. padding: 0 10px;
  467. height: 35px;
  468. }
  469. .uni-textarea-border {
  470. padding: 10px;
  471. height: 80px;
  472. }
  473. .label-box {
  474. margin-right: 10px;
  475. }
  476. .transform-scale {
  477. transform: scale(0.7);
  478. }
  479. .butto {
  480. text-align: center;
  481. }
  482. .option {
  483. padding: 20rpx;
  484. }
  485. .uni-margin-wrap {
  486. width: 690rpx;
  487. width: 100%;
  488. ;
  489. }
  490. .swiper {
  491. height: 300rpx;
  492. }
  493. .swiper-item {
  494. display: block;
  495. height: 300rpx;
  496. line-height: 300rpx;
  497. text-align: center;
  498. }
  499. .swiper-list {
  500. margin-top: 40rpx;
  501. margin-bottom: 0;
  502. }
  503. .uni-common-mt {
  504. margin-top: 60rpx;
  505. position: relative;
  506. }
  507. .info {
  508. position: absolute;
  509. right: 20rpx;
  510. }
  511. .uni-padding-wrap {
  512. width: 550rpx;
  513. padding: 0 100rpx;
  514. }
  515. .signup {
  516. box-shadow: 0rpx 5rpx 40rpx #ccc;
  517. width: 100%;
  518. position: fixed;
  519. bottom: 0rpx;
  520. display: flex;
  521. height: 90rpx;
  522. padding-top: 2%;
  523. background-color: #FFFFFF;
  524. justify-content: space-around;
  525. }
  526. .signuptext {
  527. text-align: center;
  528. margin-top: 2%;
  529. }
  530. .signuptext p {
  531. font-size: 60%;
  532. color: #333333;
  533. }
  534. .signupbut {
  535. text-align: center;
  536. margin-top: 2%;
  537. }
  538. .but1 {
  539. width: 120%;
  540. text-align: center;
  541. background-color: #FCCF41;
  542. border-radius: 10rpx;
  543. color: #464100;
  544. font-size: 28rpx;
  545. line-height: 156%;
  546. font-weight: 500;
  547. height: 65%;
  548. }
  549. /deep/.uni-searchbar__box {
  550. border-color: #267CFF !important;
  551. border-width: 2rpx !important;
  552. }
  553. /deep/.uni-searchbar__box {
  554. background-color: #FFFFFF !important;
  555. }
  556. /deep/.uni-searchbar__text-placeholder {
  557. font-size: 30rpx !important;
  558. }
  559. /deep/.segmented-control__text {
  560. font-size: 34rpx !important;
  561. }
  562. /deep/.uni-data-checklist {
  563. padding-left: 20upx;
  564. }
  565. uni-picker {
  566. position: relative;
  567. display: block;
  568. cursor: pointer;
  569. padding-left: 20rpx !important;
  570. padding-top: 14rpx !important;
  571. color: grey !important;
  572. }
  573. /deep/.uni-date-x--border {
  574. border: 0px solid #dcdfe6 !important;
  575. }
  576. /deep/.is-input-border {
  577. border: 0px solid #c8c7cc !important;
  578. }
  579. /deep/.uni-progress-info {
  580. font-size: 25rpx !important;
  581. }
  582. /deep/.uni-error-message {
  583. position: absolute;
  584. bottom: -20rpx !important;
  585. left: 20rpx !important;
  586. text-align: left;
  587. }
  588. /deep/.uni-forms-item__inner {
  589. padding-bottom: 0rpx !important;
  590. margin-bottom: 30rpx !important;
  591. border-bottom: 0.5rpx solid #CCCCCC;
  592. }
  593. /deep/.uni-group__title {
  594. background-color: #FFFFFF !important;
  595. }
  596. /deep/.uni-list-item__content-title {
  597. font-size: 30rpx !important;
  598. color: #111111 !important;
  599. }
  600. /deep/.uni-progress-bar {
  601. border-radius: 10rpx !important;
  602. }
  603. /deep/.uni-progress-inner-bar {
  604. border-radius: 10rpx !important;
  605. }
  606. /deep/.is-input-border {
  607. border-radius: 20px !important;
  608. background-color: #fff;
  609. }
  610. .uni-easyinput__content-input {
  611. font-size: 30upx !important;
  612. }
  613. .content-clear-icon {
  614. font-size: 40upx !important;
  615. }
  616. /deep/.input-box {
  617. padding: 50upx;
  618. font-size: 30upx;
  619. .input-item {
  620. display: flex;
  621. border: 1upx solid #F8F8F8;
  622. line-height: 90upx;
  623. height: 90upx;
  624. margin-top: 20upx;
  625. background: #F8F8F8;
  626. border-radius: 48upx;
  627. .input-label {
  628. width: 150upx;
  629. text-align: center;
  630. }
  631. .input-body {
  632. position: relative;
  633. height: 100upx;
  634. width: calc(100% - 150upx);
  635. .input {
  636. line-height: 90upx;
  637. height: 90upx;
  638. position: relative;
  639. font-size: 28upx;
  640. }
  641. .eye {
  642. position: absolute;
  643. height: 50upx;
  644. width: 50upx;
  645. right: 20upx;
  646. top: 50%;
  647. transform: translateY(-50%);
  648. }
  649. .btn-code {
  650. position: absolute;
  651. right: 0upx;
  652. top: 50%;
  653. transform: translateY(-50%);
  654. background: none;
  655. color: #205592;
  656. width: 160upx;
  657. font-size: 24upx;
  658. box-sizing: border-box;
  659. text-align: center;
  660. padding: 0;
  661. height: 100upx;
  662. line-height: 100upx;
  663. }
  664. }
  665. }
  666. .select {
  667. // padding-top: 40upx;
  668. display: flex;
  669. justify-content: space-between;
  670. color: #003B67;
  671. }
  672. }
  673. /deep/.title-left {
  674. width: 3px;
  675. height: 16px;
  676. background: #267CFF;
  677. display: inline-block;
  678. border-radius: 3px;
  679. margin-top: 3px;
  680. vertical-align: top;
  681. margin-right: 10px;
  682. }
  683. </style>