addressEdit.vue 8.4 KB

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