addressEdit.vue 8.4 KB

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