addressEdit.vue 6.7 KB

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