editAddress.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <view class="tui-addr-box">
  3. <form @submit="bindSave" :report-submit="true">
  4. <tui-list-cell :hover="false" padding="0">
  5. <view class="tui-line-cell">
  6. <view class="tui-title">姓名</view>
  7. <input placeholder-class="tui-phcolor" class="tui-input" name="name" :value="addressData.name"
  8. placeholder="请输入姓名" maxlength="15" type="text" />
  9. </view>
  10. </tui-list-cell>
  11. <tui-list-cell :hover="false" padding="0">
  12. <view class="tui-line-cell">
  13. <view class="tui-title">手机号码</view>
  14. <input placeholder-class="tui-phcolor" class="tui-input" name="telephone"
  15. :value="addressData.telephone" placeholder="请输入手机号码" maxlength="11" type="text" />
  16. </view>
  17. </tui-list-cell>
  18. <tui-list-cell @tap="onChangePosition" :arrow="true" padding="0">
  19. <view class="tui-line-cell">
  20. <view class="tui-title"><text class="tui-title-city-text">所在位置</text></view>
  21. <input placeholder-class="tui-phcolor" class="tui-input tui-pr__30" disabled placeholder="请选择所在位置"
  22. maxlength="50" type="text" v-model="showRegionStr" />
  23. </view>
  24. </tui-list-cell>
  25. <tui-list-cell :hover="false" padding="0">
  26. <view class="tui-line-cell">
  27. <view class="tui-title">详细地址</view>
  28. <input placeholder-class="tui-phcolor" class="tui-input" name="address" :value="addressData.address"
  29. placeholder="请输入详细的地址" maxlength="50" type="text" />
  30. </view>
  31. </tui-list-cell>
  32. <!-- 默认地址 -->
  33. <!--<tui-list-cell :hover="false" padding="0">
  34. <view class="tui-swipe-cell">
  35. <view>设为默认地址</view>
  36. <switch checked color="#19be6b" class="tui-switch-small" />
  37. </view>
  38. </tui-list-cell>-->
  39. <!-- 保存地址 -->
  40. <view class="tui-addr-save">
  41. <button form-type="submit" class="addressbutt" :style="'background:'+ pagestyleconfig.appstylecolor">保存地址</button>
  42. </view>
  43. <view class="tui-del" v-if="id > 0">
  44. <tui-button shadow type="white" @click="deleteAddress" height="88rpx" shape="circle">删除地址</tui-button>
  45. </view>
  46. </form>
  47. </view>
  48. </template>
  49. <script>
  50. const util = require("@/utils/util.js")
  51. export default {
  52. data() {
  53. return {
  54. id: 0,
  55. addressData: [],
  56. pagestyleconfig: [],
  57. lists: ["公司", "家", "学校", "其他"],
  58. pickerSelect: [0, 0, 0],
  59. showRegionStr: "",
  60. province: [],
  61. city: [],
  62. district: [],
  63. pickerRegionRange: [],
  64. is_bindingaddress: 0,
  65. telnull: '',
  66. latitude: '',
  67. longitude: '',
  68. region_name: '',
  69. province_name: '',
  70. city_name: '',
  71. district_name: '',
  72. }
  73. },
  74. onLoad(e) {
  75. const _this = this;
  76. _this.$config.init(function() {
  77. _this.telnull = _this.$config.getConf("telnull");
  78. });
  79. _this.$request.post('config', {
  80. mo: 'pagestyle'
  81. }).then(res => {
  82. if (res.errno == 0) {
  83. _this.pagestyleconfig = res.data
  84. }
  85. });
  86. _this.is_bindingaddress = e.is_bindingaddress;
  87. if (e.id) { // 修改初始化数据库数据
  88. _this.$request.get('address.detail', {
  89. samkey: (new Date()).valueOf(),
  90. id: e.id
  91. }).then(res => {
  92. if (res.errno === 0) {
  93. _this.id = e.id;
  94. _this.addressData = res.data;
  95. _this.region_name = _this.addressData.region_name;
  96. _this.province_name = _this.addressData.province_name;
  97. _this.city_name = _this.addressData.city_name;
  98. _this.district_name = _this.addressData.district_name;
  99. _this.showRegionStr = _this.province_name + _this.city_name + _this.district_name + _this
  100. .region_name;
  101. return;
  102. } else {
  103. uni.showModal({
  104. title: '提示',
  105. content: '无法获取地址数据',
  106. showCancel: false
  107. })
  108. }
  109. })
  110. }
  111. },
  112. methods: {
  113. bindSave: function(e) {
  114. var _this = this;
  115. var name = e.detail.value.name;
  116. var address = e.detail.value.address;
  117. var telephone = e.detail.value.telephone;
  118. if (name == "") {
  119. uni.showModal({
  120. title: '提示',
  121. content: '请填写联系人姓名',
  122. showCancel: false
  123. })
  124. return
  125. }
  126. if (_this.telnull != '1') {
  127. if (telephone == "") {
  128. uni.showModal({
  129. title: '提示',
  130. content: '请输入联系电话',
  131. showCancel: false
  132. })
  133. return
  134. }
  135. }
  136. if (JSON.stringify(_this.province) == "{}" || JSON.stringify(_this.city) == "{}") {
  137. uni.showModal({
  138. title: '提示',
  139. content: '请选择地区',
  140. showCancel: false
  141. })
  142. return
  143. }
  144. if (address == "") {
  145. uni.showModal({
  146. title: '提示',
  147. content: '请填写详细地址',
  148. showCancel: false
  149. })
  150. return
  151. }
  152. let apiResult
  153. if (_this.id) {
  154. apiResult = _this.$request.post('address.update', {
  155. id: _this.id,
  156. region_name: _this.region_name || _this.addressData.region_name,
  157. province_name: _this.province_name || _this.addressData.province_name,
  158. city_name: _this.city_name || _this.addressData.city_name,
  159. district_name: _this.district_name || _this.addressData.district_name,
  160. latitude: _this.latitude || _this.addressData.latitude,
  161. longitude: _this.longitude || _this.addressData.longitude,
  162. name: name,
  163. address: address,
  164. telephone: telephone,
  165. isDefault: '1'
  166. })
  167. } else {
  168. apiResult = _this.$request.post('address.add', {
  169. is_bindingaddress: _this.is_bindingaddress,
  170. region_name: _this.region_name,
  171. province_name: _this.province_name,
  172. city_name: _this.city_name,
  173. district_name: _this.district_name,
  174. latitude: _this.latitude,
  175. longitude: _this.longitude,
  176. name: name,
  177. address: address,
  178. telephone: telephone,
  179. isDefault: '1'
  180. })
  181. }
  182. apiResult.then(function(res) {
  183. if (res.errno != 0) {
  184. // 登录错误
  185. uni.hideLoading();
  186. uni.showModal({
  187. title: '失败',
  188. content: res.msg,
  189. showCancel: false
  190. })
  191. return;
  192. }
  193. // 跳转到结算页面
  194. uni.navigateBack({})
  195. })
  196. },
  197. deleteAddress: function() {
  198. var _this = this;
  199. var id = _this.addressData.id;
  200. uni.showModal({
  201. title: '提示',
  202. content: '确定要删除该地址吗?',
  203. success: function(res) {
  204. if (res.confirm) {
  205. _this.$request.post('address.delete', {
  206. id: id
  207. }).then(function() {
  208. uni.navigateBack({})
  209. })
  210. } else {
  211. console.log('user cancel')
  212. }
  213. }
  214. })
  215. },
  216. onChangePosition: function() {
  217. const _this = this;
  218. uni.chooseLocation({
  219. success(res) {
  220. _this.latitude = res.latitude;
  221. _this.longitude = res.longitude;
  222. _this.region_name = res.name;
  223. _this.$request.post('geocoder.address2area', {
  224. address:res.address,
  225. latitude: res.latitude,
  226. longitude: res.longitude
  227. }).then(apires => {
  228. //console.log(apires.data);
  229. _this.province_name = apires.data.province_name;
  230. _this.city_name = apires.data.city_name;
  231. _this.district_name = apires.data.district_name || '';
  232. _this.showRegionStr = _this.province_name + _this.city_name + _this.district_name +
  233. _this.region_name;
  234. });
  235. }
  236. });
  237. },
  238. //获取微信地址
  239. readFromWx: function() {
  240. const _this = this
  241. uni.chooseAddress({
  242. success: function(res) {
  243. //console.log(res)
  244. _this.showRegionStr = res.provinceName + res.cityName + res.countyName;
  245. _this.wxaddress = res;
  246. }
  247. })
  248. }
  249. },
  250. /**
  251. * 页面相关事件处理函数--监听用户下拉动作
  252. */
  253. onPullDownRefresh: function() {
  254. setTimeout(() => {
  255. uni.stopPullDownRefresh()
  256. }, 200);
  257. },
  258. }
  259. </script>
  260. <style>
  261. .tui-addr-box {
  262. padding: 20rpx 0;
  263. }
  264. .tui-line-cell {
  265. width: 100%;
  266. padding: 24rpx 30rpx;
  267. box-sizing: border-box;
  268. display: flex;
  269. align-items: center;
  270. }
  271. .tui-title {
  272. width: 180rpx;
  273. font-size: 28rpx;
  274. flex-shrink: 0;
  275. }
  276. .tui-title-city-text {
  277. width: 180rpx;
  278. height: 40rpx;
  279. display: block;
  280. line-height: 46rpx;
  281. }
  282. .tui-input {
  283. width: 500rpx;
  284. }
  285. .tui-pr__30 {
  286. padding-right: 30rpx;
  287. }
  288. .tui-input-city {
  289. flex: 1;
  290. height: 40rpx;
  291. font-size: 28rpx;
  292. padding-right: 30rpx;
  293. }
  294. .tui-phcolor {
  295. color: #ccc;
  296. font-size: 28rpx;
  297. }
  298. .tui-cell-title {
  299. font-size: 28rpx;
  300. flex-shrink: 0;
  301. }
  302. .tui-addr-label {
  303. margin-left: 70rpx;
  304. }
  305. .tui-label-item {
  306. width: 76rpx;
  307. height: 40rpx;
  308. border: 1rpx solid rgb(136, 136, 136);
  309. border-radius: 6rpx;
  310. font-size: 26rpx;
  311. text-align: center;
  312. line-height: 40rpx;
  313. margin-right: 20rpx;
  314. display: inline-block;
  315. transform: scale(0.92);
  316. }
  317. .tui-label-active {
  318. background: #E41F19;
  319. border-color: #E41F19;
  320. color: #fff;
  321. }
  322. .tui-swipe-cell {
  323. width: 100%;
  324. display: flex;
  325. justify-content: space-between;
  326. align-items: center;
  327. background: #fff;
  328. padding: 10rpx 24rpx;
  329. box-sizing: border-box;
  330. border-radius: 6rpx;
  331. overflow: hidden;
  332. font-size: 28rpx;
  333. }
  334. .tui-switch-small {
  335. transform: scale(0.8);
  336. transform-origin: 100% center;
  337. }
  338. /* #ifndef H5 */
  339. .tui-switch-small .wx-switch-input {
  340. margin: 0 !important;
  341. }
  342. /* #endif */
  343. /* #ifdef H5 */
  344. >>>uni-switch .uni-switch-input {
  345. margin-right: 0 !important;
  346. }
  347. /* #endif */
  348. .tui-addr-save {
  349. padding: 24rpx 30rpx;
  350. margin-top: 100rpx;
  351. }
  352. .tui-del {
  353. padding: 24rpx 30rpx;
  354. }
  355. .addressbutt {
  356. height: 88rpx;
  357. line-height: 88rpx;
  358. font-size: 28rpx;
  359. border-radius: 50rpx;
  360. color: #ffffff;
  361. align-items: center;
  362. }
  363. </style>