addressEdit.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 :className="className" :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. className: {
  82. type: String,
  83. default: ''
  84. }
  85. },
  86. data() {
  87. return {
  88. params: {
  89. area: '',
  90. detailAddress: '',
  91. email: '',
  92. tel: '',
  93. name: '',
  94. province: '',
  95. city: '',
  96. district: ''
  97. },
  98. isActive: false,
  99. addressShow: false,
  100. timeoutCount: 0,
  101. collectResult: ''
  102. }
  103. },
  104. watch: {
  105. 'data': {
  106. handler: function (newVal) {
  107. if (newVal) {
  108. newVal.num === 1 ? this.isActive = true : this.isActive = false
  109. this.params = this.baseUtils.deepCopy(newVal)
  110. }
  111. },
  112. immediate: true
  113. }
  114. },
  115. methods: {
  116. editClick (data) {
  117. this.$emit('isEditEvent', data || {}, false)
  118. },
  119. addressData (type) {
  120. this.addressShow = false
  121. if (type) {
  122. this.params.area = `${type.province},${type.city},${type.area}`
  123. this.params.province = type.province
  124. this.params.city = type.city
  125. this.params.district = type.area
  126. }
  127. },
  128. setRemindText (str) {
  129. this.collectResult = str
  130. this.timeoutCount++
  131. },
  132. storeInfosave(_tp) {
  133. this.BScroll.refresh()
  134. if (_tp === 'cancel') {
  135. this.editClick()
  136. return false
  137. }
  138. if (!this.params.name || this.params.name === '') {
  139. this.setRemindText('收货人姓名不能为空')
  140. return false
  141. }
  142. if (!this.params.tel || this.params.tel === '' || !/^1[3|4|5|6|7|8|9][0-9]{9}$/.test(this.params.tel)) {
  143. this.setRemindText('请输入正确的手机号码')
  144. return false
  145. }
  146. if (this.params.email && !/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/.test(this.params.email)) {
  147. this.setRemindText('请输入正确的邮箱')
  148. return false
  149. }
  150. if (!this.params.area || this.params.area === '') {
  151. this.setRemindText('请选择所在地区')
  152. return false
  153. }
  154. if (!this.params.detailAddress || this.params.detailAddress === '') {
  155. this.setRemindText('请填写详细地址信息')
  156. return false
  157. }
  158. this.$http.post(`/trade/address/shipping/save?isPersonal=${this.isPersonal}&isSetTop=${this.isActive}&send=${this.isSend}`, this.params)
  159. .then(res => {
  160. this.setRemindText('保存成功')
  161. this.editClick(res.data)
  162. }).catch(err => {
  163. this.collectResult = err.response.data
  164. this.timeoutCount++
  165. this.params = this.data
  166. })
  167. }
  168. },
  169. components: {
  170. RemindBox,
  171. SelectAddress
  172. },
  173. mounted() {
  174. this.$nextTick(() => {
  175. if (this.BScroll) {
  176. this.BScroll.refresh()
  177. } else {
  178. this.BScroll = new BScroll(this.$refs.addressContent, {
  179. click: true
  180. })
  181. }
  182. })
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. .shipments_address_edit{
  188. .control {
  189. width: 90%;
  190. margin: 0.4rem auto 0rem;
  191. height: .88rem;
  192. line-height: 0.88rem;
  193. .save {
  194. border-radius: 3px;
  195. width: 48%;
  196. color: #fff;
  197. text-align: center;
  198. height: .88rem;
  199. line-height: 0.88rem;
  200. background: #3e82f5;
  201. float: right;
  202. }
  203. .cancel {
  204. border-radius: 3px;
  205. width: 48%;
  206. background: #acabab;
  207. color: #fff;
  208. text-align: center;
  209. height: .88rem;
  210. line-height: 0.88rem;
  211. float: left;
  212. }
  213. }
  214. .form_line{
  215. margin:.2rem;
  216. padding:.2rem;
  217. background: #ffffff;
  218. border-radius:.05rem;
  219. ul{
  220. li{
  221. line-height: 1.2rem;
  222. height:1.2rem;
  223. border-bottom:1px solid #d3d3d3;
  224. vertical-align: middle;
  225. &:last-child{
  226. border:none;
  227. }
  228. .com_left{
  229. width:1.85rem;
  230. color:#4c8cf7;
  231. text-align: right;
  232. font-size: .28rem;
  233. span{
  234. color:#ff3333;
  235. }
  236. }
  237. .form_input{
  238. position:relative;
  239. margin-left:1.85rem;
  240. padding-right:.2rem;
  241. span{
  242. line-height: .3rem;
  243. word-break: break-all;
  244. display: inline-block;
  245. margin-right: .2rem;
  246. vertical-align: middle;
  247. }
  248. i{
  249. position:absolute;
  250. top:0;
  251. right:0;
  252. color: #c1c1c6;
  253. font-size: .28rem;
  254. }
  255. input{
  256. width:100%;
  257. line-height: .3rem;
  258. height:.3rem;
  259. border:none;
  260. font-size: .28rem;
  261. }
  262. }
  263. }
  264. }
  265. }
  266. }
  267. .fix-sa-edit {
  268. .form_line {
  269. margin-top: 0;
  270. }
  271. }
  272. </style>