Detail.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div class="eait-bg">
  3. <div class="eait-list">
  4. <div class="list-item">
  5. <div class="item-title">收货人</div>
  6. <div class="item-text">
  7. <van-field type="text" v-model="realname" placeholder="请输入收货人姓名" />
  8. </div>
  9. <!-- <div class="item-text" v-if="show">呸呸呸</div> -->
  10. <div class="clear"></div>
  11. </div>
  12. <div class="list-item">
  13. <div class="item-title">手机号</div>
  14. <div class="item-text">
  15. <van-field type="tel" v-model="tel" placeholder="请输入收货人手机号" />
  16. </div>
  17. <!-- <div class="item-text" v-if="show">呸呸呸</div> -->
  18. <div class="clear"></div>
  19. </div>
  20. <div class="list-item">
  21. <div class="item-title">选择地区</div>
  22. <div @click="clickcity">
  23. <div class="item-text" :style="cityname === '请选择收货人地区'? 'color: #bbb;': 'color: #4c4c4c;'">{{cityname}}</div>
  24. <!-- <van-field type="text" readonly v-model="address" placeholder="请选择收货人地区" /> -->
  25. <img src="@/assets/img/icon.png" class="item-icon" alt="">
  26. <!-- <div class="item-text" v-if="show">呸呸呸</div> -->
  27. <div class="clear">
  28. </div>
  29. </div>
  30. </div>
  31. <div class="list-item">
  32. <div class="item-title">详细地址</div>
  33. <div class="item-text">
  34. <van-field type="text" v-model="address1" placeholder="如街道、门牌号、小区、乡镇、村等" />
  35. </div>
  36. <!-- <div class="item-text" v-if="show">呸呸呸</div> -->
  37. <div class="clear"></div>
  38. </div>
  39. <div class="list-item">
  40. <div v-if="id">
  41. <van-switch @input="onInput()" :value="state === 0 ? checked : !checked" size="0.4rem" active-color="#28cd5e" class="change-btn" inactive-color="#cccccc" />
  42. <div v-if="!checked" class="change-text">设为默认</div>
  43. <div v-if="checked" class="change-text1">已设为默认</div>
  44. </div>
  45. <div v-if="!id">
  46. <van-switch @input="onInput()" :value="checked" size="0.4rem" active-color="#28cd5e" class="change-btn" inactive-color="#cccccc" />
  47. <div v-if="!checked" class="change-text">设为默认</div>
  48. <div v-if="checked" class="change-text1">已设为默认</div>
  49. </div>
  50. <div class="clear"></div>
  51. </div>
  52. </div>
  53. <Btn :title="titlename" @titleclick="issave" />
  54. <van-popup v-model="cityshow" position="bottom" :style="{ height: '50%', position: 'absolute' }" >
  55. <van-area :area-list="areaList1" @cancel="onCancel" @confirm="onConfirm" />
  56. </van-popup>
  57. </div>
  58. </template>
  59. <script>
  60. import Vue from 'vue'
  61. import { Switch, Toast } from 'vant'
  62. import areaList from '@/common/city'
  63. import validator from '@/common/validator'
  64. import Btn from '@/components/Btn.vue'
  65. export default {
  66. name: 'userAddressEdit',
  67. data () {
  68. return {
  69. show: false,
  70. realname: '',
  71. tel: '',
  72. address: '',
  73. address1: '',
  74. cityshow: false,
  75. cityname: '请选择收货人地区',
  76. prov: '',
  77. city: '',
  78. area: '',
  79. titlename: '保存',
  80. detail: {},
  81. state: false,
  82. checked: false,
  83. id: 0
  84. }
  85. },
  86. computed: {},
  87. methods: {
  88. validate () {
  89. let msg
  90. if (!validator.required(this.realname)) {
  91. msg = '姓名不能为空'
  92. } else if (!validator.required(this.tel)) {
  93. msg = '手机号码不能为空'
  94. } else if (!validator.telphone(this.tel)) {
  95. msg = '手机号码格式不正确'
  96. } else if (!validator.required(this.prov)) {
  97. msg = '省市区不能为空'
  98. } else if (!validator.required(this.address1)) {
  99. msg = '详细地址不能为空'
  100. }
  101. return { isOk: !msg, msg }
  102. },
  103. issave () {
  104. let { isOk, msg } = this.validate()
  105. if (isOk) {
  106. this.save()
  107. } else {
  108. Toast({
  109. message: msg,
  110. duration: 2000
  111. })
  112. }
  113. },
  114. onInput () {
  115. this.checked = !this.checked
  116. },
  117. getdetail () {
  118. this.$get({
  119. url: `v1/address/${Number(this.$route.query.id)}`,
  120. data: {
  121. }
  122. }).then((res) => {
  123. this.detail = res
  124. this.realname = res.contact
  125. this.tel = res.tel
  126. this.prov = res.province
  127. this.city = res.city
  128. this.area = res.district
  129. this.cityname = res.province + ' ' + res.city + ' ' + res.district
  130. this.address1 = res.address
  131. this.state = res.state
  132. })
  133. },
  134. save () {
  135. if (this.checked === false) {
  136. var ischeacked = 0
  137. } else {
  138. ischeacked = 1
  139. }
  140. if (this.id) {
  141. this.$put({
  142. url: 'v1/address/' + Number(this.id),
  143. data: {
  144. province: this.prov,
  145. city: this.city,
  146. district: this.area,
  147. address: this.address1,
  148. tel: this.tel,
  149. contact: this.realname,
  150. // state: ischeacked,
  151. set_default: ischeacked
  152. // address_id: Number(this.id)
  153. }
  154. }).then((res) => {
  155. console.log(res)
  156. Toast('保存成功')
  157. this.$router.back()
  158. })
  159. } else {
  160. if (this.$route.query.one && ischeacked === 0) {
  161. Toast({
  162. message: '请把新增的首个地址设为默认地址',
  163. duration: 2000
  164. })
  165. } else {
  166. this.$post({
  167. url: 'v1/address',
  168. data: {
  169. province: this.prov,
  170. city: this.city,
  171. district: this.area,
  172. address: this.address1,
  173. tel: this.tel,
  174. contact: this.realname,
  175. set_default: ischeacked
  176. // address_id: Number(this.$route.params.id)
  177. }
  178. }).then((res) => {
  179. console.log(res)
  180. Toast('保存成功')
  181. // this.$router.push({ path: `/user/address/list` })
  182. this.$router.back()
  183. })
  184. }
  185. }
  186. },
  187. clickcity () {
  188. this.cityshow = true
  189. },
  190. onCancel () {
  191. this.cityshow = false
  192. },
  193. onConfirm (e) {
  194. var citydata = e
  195. this.cityname = citydata[0].name + ' ' + citydata[1].name + ' ' + citydata[2].name
  196. this.prov = citydata[0].name
  197. this.city = citydata[1].name
  198. this.area = citydata[2].name
  199. this.cityshow = false
  200. }
  201. },
  202. created () {
  203. Vue.use(Switch)
  204. this.areaList1 = areaList
  205. this.id = this.$route.query.id
  206. if (this.$route.query.id) {
  207. this.getdetail()
  208. }
  209. },
  210. watch: {},
  211. components: {
  212. Btn
  213. }
  214. }
  215. </script>
  216. <style lang='less' scoped>
  217. .eait-bg {
  218. /deep/ .van-picker__cancel {
  219. color: #28cd5e;
  220. }
  221. /deep/ .van-picker__confirm {
  222. color: #28cd5e;
  223. }
  224. background: #eeeeed;
  225. min-height: 100%;
  226. overflow: hidden;
  227. text-align: left;
  228. .eait-list {
  229. background: #fff;
  230. box-sizing: border-box;
  231. padding: 0 0.2rem;
  232. .list-item {
  233. height: 0.98rem;
  234. width: 100%;
  235. border-bottom: 0.02rem solid #eeeeee;
  236. line-height: 0.98rem;
  237. font-size: 0.26rem;
  238. color: #4c4c4c;
  239. .change-btn {
  240. float: left;
  241. margin-top: 0.3rem;
  242. }
  243. .change-text {
  244. float: left;
  245. color: #999;
  246. font-size: 0.26rem;
  247. margin-top: 0.05rem;
  248. margin-left: 0.15rem;
  249. }
  250. .change-text1 {
  251. float: left;
  252. color: #28cd5e;
  253. font-size: 0.26rem;
  254. margin-top: 0.05rem;
  255. margin-left: 0.15rem;
  256. }
  257. .item-title {
  258. float: left;
  259. width: 1.6rem;
  260. // margin-right: 0.4rem;
  261. text-align: left;
  262. }
  263. .item-text {
  264. float: left;
  265. width: 5rem;
  266. text-align: left;
  267. .van-cell {
  268. padding-left: 0;
  269. padding-top: 0.28rem;
  270. height: 100%;
  271. }
  272. }
  273. .item-icon {
  274. float: right;
  275. width: 0.12rem;
  276. height: 0.2rem;
  277. margin-top: 0.35rem;
  278. }
  279. }
  280. }
  281. }
  282. </style>