newModule.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="select-layout">
  3. <div class="address-input-con">
  4. <div class="address-input-item">
  5. <div class="address-sub address-name">
  6. <div class="top-title">{{ $t('mall.receiver') }}</div>
  7. <div class="ant-input">
  8. <input v-model="tempAddress.shipName" type="text" :placeholder="langAccount.placeholder.name" maxlength="10" />
  9. </div>
  10. </div>
  11. </div>
  12. <div class="address-input-item">
  13. <div class="address-sub address-phone">
  14. <div class="top-title">{{ $t('mall.phone') }}</div>
  15. <div class="ant-input">
  16. <input v-model="tempAddress.shipMobile" oninput="value=value.replace(/[^\d]/g,'')" maxlength='11' type="text" :placeholder="langAccount.placeholder.phone" />
  17. </div>
  18. </div>
  19. </div>
  20. <div class="address-input-item">
  21. <div class="address-sub prov-name">
  22. <div class="top-title">{{$t('mall.receiveAddress')}}</div>
  23. <div class="ant-input prov" @click="handleSelect('prov')">
  24. {{citylist[currentPID]['p']||'省份'}}
  25. <ul v-if="prov">
  26. <li v-for="(item,i) in citylist" :key="i" @click="handleClick('currentPID',i)">{{item.p}}</li>
  27. </ul>
  28. </div>
  29. </div>
  30. <div class="address-sub prov-name">
  31. <div class="top-title notrequired"></div>
  32. <div class="ant-input city" @click.stop="handleSelect('city')">
  33. {{currentProv[currentCID]['n']||'城市'}}
  34. <ul v-if="city">
  35. <li v-for="(item,i) in currentProv" :key="i" @click="handleClick('currentCID',i)">{{item.n}}</li>
  36. </ul>
  37. </div>
  38. </div>
  39. <div class="address-sub prov-name">
  40. <div class="top-title notrequired"></div>
  41. <div class="ant-input city" @click.stop="handleSelect('dist')">
  42. {{currentCity[currentSID]['s']||'区/县'}}
  43. <ul v-if="dist">
  44. <li v-for="(item,i) in currentCity" :key="i" @click="handleClick('currentSID',i)">{{item.s}}</li>
  45. </ul>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="address-input-item">
  50. <div class="address-sub">
  51. <!-- <div class="top-title">{{langAccount.placeholder.address}}</div> -->
  52. <div class="ant-input">
  53. <input v-model="tempAddress.shipAddress" type="text" :placeholder="langAccount.placeholder.address" maxlength="50" />
  54. </div>
  55. </div>
  56. </div>
  57. <div class="address-input-item">
  58. <p class="p-dec">{{ langAccount.recaddress }}</p>
  59. </div>
  60. <div class="actions-w">
  61. <button type="submit" class="ant-btn ant-btn-primary cancel" @click="$emit('cancle', true)">
  62. <span>{{langAccount.cancel}}</span>
  63. </button>
  64. <button type="submit" class="ant-btn ant-btn-primary" @click="uAddress">
  65. <span>{{langAccount.save}}</span>
  66. </button>
  67. </div>
  68. </div>
  69. </div>
  70. </template>
  71. <script>
  72. import { citylist } from './city'
  73. import { mapState } from 'vuex'
  74. let sle = ['prov', 'city', 'dist']
  75. var cloneObj = function (obj) {
  76. var newObj = {}
  77. if (obj instanceof Array) {
  78. newObj = []
  79. }
  80. for (var key in obj) {
  81. var val = obj[key] || ''
  82. newObj[key] = typeof val === 'object' ? cloneObj(val) : val
  83. }
  84. return newObj
  85. }
  86. export default {
  87. props: ['address', 'token'],
  88. data () {
  89. let idArr = ['', '', '']
  90. if (this.address.shipAreaPath) {
  91. let tempArr = this.address.shipAreaPath.split(',')
  92. let [p, c, d] = tempArr
  93. idArr = (() => {
  94. let tmp = []
  95. citylist.forEach((item, index) => {
  96. if (item.p === p) {
  97. tmp.push(index)
  98. item.c.forEach((t2, i2) => {
  99. if (t2.n === c) {
  100. tmp.push(i2)
  101. t2.a.forEach((t3, i3) => {
  102. if (t3.s === d) {
  103. tmp.push(i3)
  104. }
  105. })
  106. }
  107. })
  108. }
  109. })
  110. return tmp
  111. })()
  112. }
  113. return {
  114. citylist,
  115. prov: false,
  116. city: false,
  117. dist: false,
  118. currentPID: idArr[0] || 18,
  119. currentCID: idArr[1] || 3,
  120. currentSID: idArr[2] || 2,
  121. areaPath: cloneObj(this.address.areaPath)
  122. }
  123. },
  124. computed: {
  125. ...mapState({
  126. langAccount: state => state.language.home.manage.account
  127. }),
  128. tempAddress: function () {
  129. return cloneObj(this.address)
  130. },
  131. currentProv: function () {
  132. let tmp = this.citylist[this.currentPID]
  133. return tmp.c
  134. },
  135. currentCity: function () {
  136. let cprov = this.citylist[this.currentPID]
  137. let tmp = cprov.c[this.currentCID]
  138. return tmp.a
  139. }
  140. },
  141. watch: {
  142. currentProv () {
  143. this.currentCID = 0
  144. this.currentSID = 0
  145. }
  146. },
  147. methods: {
  148. uAddress () {
  149. this.tempAddress.province = this.areaPath[0]
  150. this.tempAddress.city = this.areaPath[1]
  151. this.tempAddress.shipAreaPath = this.areaPath.join(',')
  152. let {
  153. shipAddress,
  154. shipAreaPath,
  155. province,
  156. city,
  157. shipMobile,
  158. shipName
  159. } = this.tempAddress
  160. let isObject = function (obj) {
  161. return JSON.stringify(obj) === '{}' ? '' : obj
  162. }
  163. let params = {
  164. shipAddress,
  165. shipAreaPath,
  166. province,
  167. city,
  168. shipMobile,
  169. shipName
  170. }
  171. let test = Object.keys(params)
  172. console.log(test, params)
  173. for (let i = 0; i < test.length; i++) {
  174. if (!isObject(params[test[i]])) {
  175. return this.$toast.show('warn', this.langAccount.fill)
  176. }
  177. }
  178. params['id'] = this.address.id
  179. let url = this.address.id ? 'updateAddress' : 'insertAddress'
  180. this.$http
  181. .post(`/user/${url}`, params, {
  182. headers: {
  183. token: this.token
  184. }
  185. })
  186. .then(data => {
  187. let res = data.data
  188. if (res.code === 0) {
  189. this.$emit('closeSelect', true)
  190. this.$store.dispatch('getInfo', {
  191. url: '/user/getReceiverInfo',
  192. name: 'address'
  193. })
  194. this.$emit('submit', params)
  195. }
  196. })
  197. },
  198. handleSelect (item) {
  199. sle.forEach(i => {
  200. console.log(i, item)
  201. if (i === item) {
  202. this[i] = !this[i]
  203. } else {
  204. this[i] = false
  205. }
  206. })
  207. },
  208. handleClick (id, i) {
  209. this[id] = i
  210. this.handleChange()
  211. },
  212. handleChange () {
  213. setTimeout(() => {
  214. let prov = this.citylist[this.currentPID]
  215. let city = prov.c[this.currentCID]
  216. let dist = city.a[this.currentSID]
  217. this.areaPath = [prov.p, city.n, dist.s]
  218. })
  219. }
  220. },
  221. mounted () {
  222. this.handleChange()
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. @import './style.scss';
  228. </style>