addressEdit.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div>
  3. <div class="shipments_address_edit" :class="{'fix-sa-edit': inFix}">
  4. <div class="form_line">
  5. <ul class="list-unstyled" ref="addressContent">
  6. <li class="clearfix">
  7. <div class="com_left pull-left"><span>*</span>收货人姓名:</div>
  8. <div class="form_input">
  9. <input type="text" placeholder="请输入您的姓名" v-model="params.name" maxlength="10">
  10. </div>
  11. </li>
  12. <li class="clearfix">
  13. <div class="com_left pull-left"><span>*</span>联系电话:</div>
  14. <div class="form_input">
  15. <input type="tel" placeholder="请输入您的联系电话" v-model="params.tel" maxlength="11">
  16. </div>
  17. </li>
  18. <li class="clearfix">
  19. <div class="com_left pull-left">邮箱:</div>
  20. <div class="form_input">
  21. <input type="email" placeholder="请输入正确邮箱,用于接收订单提醒" v-model="params.email">
  22. </div>
  23. </li>
  24. <li class="clearfix">
  25. <div class="com_left pull-left"><span>*</span>所在地区:</div>
  26. <div class="form_input" @click="addressShow = true">
  27. <span v-text="params.area || '选择地区'">选择地区</span>
  28. <i class="iconfont icon-xiangyou"></i>
  29. </div>
  30. </li>
  31. <li class="clearfix">
  32. <div class="com_left pull-left"><span>*</span>详细地址:</div>
  33. <div class="form_input">
  34. <input type="text" placeholder="请您填写详细地址,街道名、门牌号等" v-model="params.detailAddress" maxlength="30">
  35. </div>
  36. </li>
  37. <li class="clearfix">
  38. <div class="com_left pull-left"><span>*</span>默认地址:</div>
  39. <div class="form_input">
  40. <el-switch
  41. v-model="isActive"
  42. on-text="ON"
  43. off-text="OFF">
  44. </el-switch>
  45. </div>
  46. </li>
  47. </ul>
  48. </div>
  49. <div class="control clearfix">
  50. <div class="cancel" @click="storeInfosave('cancel')">取消</div>
  51. <div class="save" @click="storeInfosave()">保存</div>
  52. </div>
  53. </div>
  54. <select-address :inFix="inFix" :isShow="addressShow" @closeAction="addressData"></select-address>
  55. <remind-box :title="collectResult" :timeoutCount="timeoutCount"></remind-box>
  56. </div>
  57. </template>
  58. <script>
  59. import BScroll from 'better-scroll'
  60. import { RemindBox } from '~components/mobile/common'
  61. import SelectAddress from './SelectAddress.vue'
  62. export default {
  63. name: 'AddressEditView',
  64. props: {
  65. data: {
  66. type: Object,
  67. default: {}
  68. },
  69. isSend: {
  70. default: true,
  71. type: Boolean
  72. },
  73. isPersonal: {
  74. default: true,
  75. type: Boolean
  76. },
  77. inFix: {
  78. type: Boolean,
  79. default: false
  80. }
  81. },
  82. data() {
  83. return {
  84. params: {
  85. area: '',
  86. detailAddress: '',
  87. email: '',
  88. tel: '',
  89. name: '',
  90. province: '',
  91. city: '',
  92. district: ''
  93. },
  94. isActive: false,
  95. addressShow: false,
  96. timeoutCount: 0,
  97. collectResult: ''
  98. }
  99. },
  100. watch: {
  101. 'data': {
  102. handler: function (newVal) {
  103. if (newVal) {
  104. newVal.num === 1 ? this.isActive = true : this.isActive = false
  105. this.params = this.baseUtils.deepCopy(newVal)
  106. }
  107. },
  108. immediate: true
  109. }
  110. },
  111. methods: {
  112. editClick (data) {
  113. this.$emit('isEditEvent', data || {}, false)
  114. },
  115. addressData (type) {
  116. this.addressShow = false
  117. if (type) {
  118. this.params.area = `${type.province},${type.city},${type.area}`
  119. this.params.province = type.province
  120. this.params.city = type.city
  121. this.params.district = type.area
  122. }
  123. },
  124. setRemindText (str) {
  125. this.collectResult = str
  126. this.timeoutCount++
  127. },
  128. storeInfosave(_tp) {
  129. this.BScroll.refresh()
  130. if (_tp === 'cancel') {
  131. this.editClick()
  132. return false
  133. }
  134. if (!this.params.name || this.params.name === '') {
  135. this.setRemindText('收货人姓名不能为空')
  136. return false
  137. }
  138. if (!this.params.tel || this.params.tel === '' || !/^1[3|4|5|6|7|8|9][0-9]{9}$/.test(this.params.tel)) {
  139. this.setRemindText('请输入正确的手机号码')
  140. return false
  141. }
  142. if (this.params.email && !/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/.test(this.params.email)) {
  143. this.setRemindText('请输入正确的邮箱')
  144. return false
  145. }
  146. if (!this.params.area || this.params.area === '') {
  147. this.setRemindText('请选择所在地区')
  148. return false
  149. }
  150. if (!this.params.detailAddress || this.params.detailAddress === '') {
  151. this.setRemindText('请填写详细地址信息')
  152. return false
  153. }
  154. this.$http.post(`/trade/address/shipping/save?isPersonal=${this.isPersonal}&isSetTop=${this.isActive}&send=${this.isSend}`, this.params)
  155. .then(res => {
  156. this.setRemindText('保存成功')
  157. this.editClick(res.data)
  158. }).catch(err => {
  159. this.collectResult = err.response.data
  160. this.timeoutCount++
  161. this.params = this.data
  162. })
  163. }
  164. },
  165. components: {
  166. RemindBox,
  167. SelectAddress
  168. },
  169. mounted() {
  170. this.$nextTick(() => {
  171. if (this.BScroll) {
  172. this.BScroll.refresh()
  173. } else {
  174. this.BScroll = new BScroll(this.$refs.addressContent, {
  175. click: true
  176. })
  177. }
  178. })
  179. }
  180. }
  181. </script>
  182. <style lang="scss" scoped>
  183. .shipments_address_edit{
  184. .control {
  185. width: 90%;
  186. margin: 0.4rem auto 0rem;
  187. height: .88rem;
  188. line-height: 0.88rem;
  189. .save {
  190. border-radius: 3px;
  191. width: 48%;
  192. color: #fff;
  193. text-align: center;
  194. height: .88rem;
  195. line-height: 0.88rem;
  196. background: #3e82f5;
  197. float: right;
  198. }
  199. .cancel {
  200. border-radius: 3px;
  201. width: 48%;
  202. background: #acabab;
  203. color: #fff;
  204. text-align: center;
  205. height: .88rem;
  206. line-height: 0.88rem;
  207. float: left;
  208. }
  209. }
  210. .form_line{
  211. margin:.2rem;
  212. padding:.2rem;
  213. background: #ffffff;
  214. border-radius:.05rem;
  215. ul{
  216. li{
  217. line-height: 1.2rem;
  218. height:1.2rem;
  219. border-bottom:1px solid #d3d3d3;
  220. vertical-align: middle;
  221. &:last-child{
  222. border:none;
  223. }
  224. .com_left{
  225. width:1.85rem;
  226. color:#4c8cf7;
  227. text-align: right;
  228. font-size: .28rem;
  229. span{
  230. color:#ff3333;
  231. }
  232. }
  233. .form_input{
  234. position:relative;
  235. margin-left:1.85rem;
  236. padding-right:.2rem;
  237. span{
  238. line-height: .3rem;
  239. word-break: break-all;
  240. display: inline-block;
  241. margin-right: .2rem;
  242. vertical-align: middle;
  243. }
  244. i{
  245. position:absolute;
  246. top:0;
  247. right:0;
  248. color: #c1c1c6;
  249. font-size: .28rem;
  250. }
  251. input{
  252. width:100%;
  253. line-height: .3rem;
  254. height:.3rem;
  255. border:none;
  256. font-size: .28rem;
  257. }
  258. }
  259. }
  260. }
  261. }
  262. }
  263. .fix-sa-edit {
  264. .form_line {
  265. margin-top: 0;
  266. }
  267. }
  268. </style>