addlocation.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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: "收货地址管理1",
  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---->",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. console.log("addressId_____",this.address_id)
  241. this.$https.post('/youngee/c/t/p/update-talent-address', {
  242. address_id: this.address_id,
  243. region_code: this.formData.fregion,
  244. detail_addr: this.formData.detailregion,
  245. phone_number: this.formData.phone,
  246. receiver_name: this.formData.name,
  247. })
  248. .then(res => {
  249. console.log("/youngee/c/t/p/update-talent-address",res)
  250. uni.navigateBack()
  251. })
  252. } else {
  253. this.$https.post('/youngee/c/t/p/add-talent-address', {
  254. region_code: this.formData.fregion,
  255. detail_addr: this.formData.detailregion,
  256. phone_number: this.formData.phone,
  257. receiver_name: this.formData.name,
  258. default_tag: this.formData.setdefault
  259. })
  260. .then(res => {
  261. console.log(res)
  262. uni.navigateBack()
  263. })
  264. }
  265. }).catch(err => {
  266. console.error('验证失败:', errors)
  267. uni.showToast({
  268. title: '请填写所有信息',
  269. icon: 'none'
  270. })
  271. })
  272. },
  273. //城市选择
  274. pickerChange(e) {
  275. // console.log(e, '1');
  276. console.log("pickerChange e.detail.value: ", e.detail.value)
  277. this.regionIndex = e.detail.value;
  278. this.regionStr = this.region[0][this.regionIndex[0]].name + ' ' + this.region[1][this.regionIndex[1]]
  279. .name + ' ' +
  280. this.region[2][this.regionIndex[2]].name;
  281. // 组件传值
  282. this.$emit('region', [this.region[0][this.regionIndex[0]].code, this.region[1][this.regionIndex[1]].code,
  283. this.region[
  284. 2][this.regionIndex[2]].code
  285. ]);
  286. this.formData.fregion = this.region[2][this.regionIndex[2]].code;
  287. console.log(this.formData.fregion)
  288. },
  289. pickerColumnchange(e) {
  290. if (e.detail.column === 0) {
  291. // 声明城市数组
  292. let cityArr = [];
  293. let countyArr = [];
  294. // 设置下标
  295. this.regionIndex = [e.detail.value, 0, 0];
  296. // 改变城市列表
  297. this.region[1] = this.oldRegion[e.detail.value].children.map(item => {
  298. cityArr.push({
  299. name: item.name,
  300. code: item.code
  301. });
  302. })
  303. this.$set(this.region, 1, cityArr);
  304. // 改变县区列表
  305. this.oldRegion[e.detail.value].children[0].children.map(item => {
  306. countyArr.push({
  307. name: item.name,
  308. code: item.code
  309. });
  310. })
  311. this.$set(this.region, 2, countyArr);
  312. }
  313. if (e.detail.column === 1) {
  314. this.regionIndex[1] = e.detail.value;
  315. this.regionIndex[2] = 0;
  316. let countyArr = [];
  317. this.oldRegion[this.regionIndex[0]].children[this.regionIndex[1]].children.map(item => {
  318. countyArr.push({
  319. name: item.name,
  320. code: item.code
  321. });
  322. })
  323. this.$set(this.region, 2, countyArr);
  324. }
  325. if (e.detail.column === 2) {
  326. this.regionIndex[2] = e.detail.value;
  327. }
  328. }
  329. },
  330. created() {
  331. let provinceArr = [];
  332. let cityArr = [];
  333. this.oldRegion.map((item, index) => {
  334. this.region[0].push({
  335. name: item.name,
  336. code: item.code
  337. });
  338. if (this.previnceId == item.code) {
  339. provinceArr = item.children;
  340. this.regionIndex[0] = index;
  341. }
  342. })
  343. // console.log(provinceArr);
  344. provinceArr.map((item, index) => {
  345. this.region[1].push({
  346. name: item.name,
  347. code: item.code
  348. });
  349. if (this.cityId == item.code) {
  350. cityArr = item.children;
  351. this.regionIndex[1] = index;
  352. }
  353. })
  354. cityArr.map((item, index) => {
  355. this.region[2].push({
  356. name: item.name,
  357. code: item.code
  358. });
  359. if (this.countyId == item.code)
  360. this.regionIndex[2] = index;
  361. })
  362. if (this.isRevise)
  363. this.regionStr = this.region[0][this.regionIndex[0]].name + ' ' + this.region[1][this.regionIndex[1]]
  364. .name + ' ' + this.region[2][this.regionIndex[2]].name;
  365. else
  366. this.regionStr = '请选择省市区';
  367. }
  368. };
  369. </script>
  370. <style>
  371. picker {
  372. position: relative;
  373. display: block;
  374. cursor: pointer;
  375. padding-left: 20rpx !important;
  376. /* padding-top: 14rpx !important;
  377. color: grey !important; */
  378. }
  379. /deep/.uni-forms-item__inner {
  380. border-bottom: none !important;
  381. margin-bottom: 0 !important;
  382. }
  383. </style>
  384. <style lang="scss" scoped>
  385. @charset "UTF-8";
  386. /* 头条小程序组件内不能引入字体 */
  387. /* #ifdef MP-TOUTIAO */
  388. @font-face {
  389. font-family: uniicons;
  390. font-weight: normal;
  391. font-style: normal;
  392. src: url("~@/static/uni.ttf") format("truetype");
  393. }
  394. /* #endif */
  395. /* #ifndef APP-NVUE */
  396. page {
  397. display: flex;
  398. flex-direction: column;
  399. box-sizing: border-box;
  400. background-color: #FFFFFF;
  401. min-height: 100%;
  402. height: auto;
  403. }
  404. view {
  405. font-size: 14px;
  406. line-height: inherit;
  407. }
  408. .menu {
  409. position: fixed;
  410. top: 180rpx;
  411. background-color: #FFFFFF;
  412. justify-content: space-around;
  413. height: 5%;
  414. width: 100%;
  415. display: flex;
  416. z-index: 10;
  417. margin-bottom: 10rpx;
  418. }
  419. .menu-item p {
  420. font-weight: 600;
  421. font-size: 90%;
  422. &.lor {
  423. border-bottom: 5rpx solid #F0D232;
  424. color: #F0D232;
  425. padding-bottom: 15rpx;
  426. }
  427. }
  428. .setdeault {
  429. display: flex;
  430. justify-content: space-between;
  431. }
  432. .btn1 {
  433. margin: 30rpx;
  434. font-size: 35rpx;
  435. color: #000;
  436. background-color: #F0D232;
  437. border: none;
  438. border-radius: 0;
  439. }
  440. .example {
  441. padding: 0 15px 15px;
  442. }
  443. .example-info {
  444. padding: 15px;
  445. color: #3b4144;
  446. background: #ffffff;
  447. }
  448. .example-body {
  449. /* #ifndef APP-NVUE */
  450. display: flex;
  451. /* #endif */
  452. flex-direction: row;
  453. flex-wrap: wrap;
  454. justify-content: center;
  455. padding: 0;
  456. font-size: 14px;
  457. background-color: #ffffff;
  458. }
  459. /* #endif */
  460. .example {
  461. padding: 0 15px;
  462. }
  463. .example-info {
  464. /* #ifndef APP-NVUE */
  465. display: block;
  466. /* #endif */
  467. padding: 15px;
  468. color: #3b4144;
  469. background-color: #ffffff;
  470. font-size: 14px;
  471. line-height: 20px;
  472. }
  473. .example-info-text {
  474. font-size: 14px;
  475. line-height: 20px;
  476. color: #3b4144;
  477. }
  478. .example-body {
  479. flex-direction: column;
  480. padding: 15px;
  481. background-color: #ffffff;
  482. }
  483. .word-btn-white {
  484. font-size: 18px;
  485. color: #FFFFFF;
  486. }
  487. .word-btn {
  488. /* #ifndef APP-NVUE */
  489. display: flex;
  490. /* #endif */
  491. flex-direction: row;
  492. align-items: center;
  493. justify-content: center;
  494. border-radius: 6px;
  495. height: 48px;
  496. margin: 15px;
  497. background-color: #007AFF;
  498. }
  499. .word-btn--hover {
  500. background-color: #4ca2ff;
  501. }
  502. .example {
  503. padding: 0 10px 10px;
  504. }
  505. .uni-input-border,
  506. .uni-textarea-border {
  507. flex: 1;
  508. font-size: 14px;
  509. color: #666;
  510. border: 1px #FFFFFF solid;
  511. border-radius: 5px;
  512. /* #ifndef APP-NVUE */
  513. box-sizing: border-box;
  514. /* #endif */
  515. }
  516. .uni-input-border {
  517. padding: 0 10px;
  518. height: 35px;
  519. }
  520. .uni-textarea-border {
  521. padding: 10px;
  522. height: 80px;
  523. }
  524. .label-box {
  525. margin-right: 10px;
  526. }
  527. .transform-scale {
  528. transform: scale(0.7);
  529. }
  530. .butto {
  531. text-align: center;
  532. }
  533. .option {
  534. padding: 20rpx;
  535. }
  536. .uni-margin-wrap {
  537. width: 690rpx;
  538. width: 100%;
  539. ;
  540. }
  541. .swiper {
  542. height: 300rpx;
  543. }
  544. .swiper-item {
  545. display: block;
  546. height: 300rpx;
  547. line-height: 300rpx;
  548. text-align: center;
  549. }
  550. .swiper-list {
  551. margin-top: 40rpx;
  552. margin-bottom: 0;
  553. }
  554. .uni-common-mt {
  555. margin-top: 60rpx;
  556. position: relative;
  557. }
  558. .info {
  559. position: absolute;
  560. right: 20rpx;
  561. }
  562. .uni-padding-wrap {
  563. width: 550rpx;
  564. padding: 0 100rpx;
  565. }
  566. .signup {
  567. box-shadow: 0rpx 5rpx 40rpx #ccc;
  568. width: 100%;
  569. position: fixed;
  570. bottom: 0rpx;
  571. display: flex;
  572. height: 90rpx;
  573. padding-top: 2%;
  574. background-color: #FFFFFF;
  575. justify-content: space-around;
  576. }
  577. .signuptext {
  578. text-align: center;
  579. margin-top: 2%;
  580. }
  581. .signuptext p {
  582. font-size: 60%;
  583. color: #333333;
  584. }
  585. .signupbut {
  586. text-align: center;
  587. margin-top: 2%;
  588. }
  589. .but1 {
  590. width: 120%;
  591. text-align: center;
  592. background-color: #FCCF41;
  593. border-radius: 10rpx;
  594. color: #464100;
  595. font-size: 28rpx;
  596. line-height: 156%;
  597. font-weight: 500;
  598. height: 65%;
  599. }
  600. /deep/.uni-searchbar__box {
  601. border-color: #267CFF !important;
  602. border-width: 2rpx !important;
  603. }
  604. /deep/.uni-searchbar__box {
  605. background-color: #FFFFFF !important;
  606. }
  607. /deep/.uni-searchbar__text-placeholder {
  608. font-size: 30rpx !important;
  609. }
  610. /deep/.segmented-control__text {
  611. font-size: 34rpx !important;
  612. }
  613. /deep/.uni-data-checklist {
  614. padding-left: 20upx;
  615. }
  616. uni-picker {
  617. position: relative;
  618. display: block;
  619. cursor: pointer;
  620. padding-left: 20rpx !important;
  621. // padding-top: 14rpx !important;
  622. // color: grey !important;
  623. }
  624. /deep/.uni-date-x--border {
  625. border: 0px solid #dcdfe6 !important;
  626. }
  627. /deep/.is-input-border {
  628. border: 0px solid #c8c7cc !important;
  629. }
  630. /deep/.uni-progress-info {
  631. font-size: 25rpx !important;
  632. }
  633. /deep/.uni-error-message {
  634. position: absolute;
  635. bottom: -20rpx !important;
  636. left: 20rpx !important;
  637. text-align: left;
  638. }
  639. /deep/.uni-forms-item__inner {
  640. padding-bottom: 0rpx !important;
  641. margin-bottom: 30rpx !important;
  642. border-bottom: 0.5rpx solid #CCCCCC;
  643. }
  644. /deep/.uni-group__title {
  645. background-color: #FFFFFF !important;
  646. }
  647. /deep/.uni-list-item__content-title {
  648. font-size: 30rpx !important;
  649. color: #111111 !important;
  650. }
  651. /deep/.uni-progress-bar {
  652. border-radius: 10rpx !important;
  653. }
  654. /deep/.uni-progress-inner-bar {
  655. border-radius: 10rpx !important;
  656. }
  657. /deep/.is-input-border {
  658. border-radius: 20px !important;
  659. background-color: #fff;
  660. }
  661. .uni-easyinput__content-input {
  662. font-size: 30upx !important;
  663. }
  664. .content-clear-icon {
  665. font-size: 40upx !important;
  666. }
  667. /deep/.input-box {
  668. padding: 50upx;
  669. font-size: 30upx;
  670. .input-item {
  671. display: flex;
  672. border: 1upx solid #F8F8F8;
  673. line-height: 90upx;
  674. height: 90upx;
  675. margin-top: 20upx;
  676. background: #F8F8F8;
  677. border-radius: 48upx;
  678. .input-label {
  679. width: 150upx;
  680. text-align: center;
  681. }
  682. .input-body {
  683. position: relative;
  684. height: 100upx;
  685. width: calc(100% - 150upx);
  686. .input {
  687. line-height: 90upx;
  688. height: 90upx;
  689. position: relative;
  690. font-size: 28upx;
  691. }
  692. .eye {
  693. position: absolute;
  694. height: 50upx;
  695. width: 50upx;
  696. right: 20upx;
  697. top: 50%;
  698. transform: translateY(-50%);
  699. }
  700. .btn-code {
  701. position: absolute;
  702. right: 0upx;
  703. top: 50%;
  704. transform: translateY(-50%);
  705. background: none;
  706. color: #205592;
  707. width: 160upx;
  708. font-size: 24upx;
  709. box-sizing: border-box;
  710. text-align: center;
  711. padding: 0;
  712. height: 100upx;
  713. line-height: 100upx;
  714. }
  715. }
  716. }
  717. .select {
  718. // padding-top: 40upx;
  719. display: flex;
  720. justify-content: space-between;
  721. color: #003B67;
  722. }
  723. }
  724. /deep/.title-left {
  725. width: 3px;
  726. height: 16px;
  727. background: #267CFF;
  728. display: inline-block;
  729. border-radius: 3px;
  730. margin-top: 3px;
  731. vertical-align: top;
  732. margin-right: 10px;
  733. }
  734. </style>