addressEdit.vue 7.2 KB

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