addressEdit.vue 8.7 KB

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