addressEdit.vue 8.9 KB

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