addlocation.vue 17 KB

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