addlocation.vue 17 KB

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