addphone.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="box">
  3. <view class="main">
  4. <view class="phoneListBox">
  5. <view class="phoneLine">
  6. <view class="phoneLeft">
  7. 姓名:
  8. </view>
  9. <view>
  10. <input type="text" value="" placeholder-style="color:#999999" placeholder="请输入" class="lineInput" v-model="name"/>
  11. </view>
  12. </view>
  13. <view class="phoneLine">
  14. <view class="phoneLeft">
  15. 手机号:
  16. </view>
  17. <view>
  18. <input type="text" value="" placeholder-style="color:#999999" placeholder="请输入" class="lineInput" v-model="phone"/>
  19. </view>
  20. </view>
  21. <view class="phoneLine2" style="display: flex;justify-content: space-between;">
  22. <view class="DefaultTxt">设为默认联系人</view>
  23. <view class="lineRight">
  24. <switch :checked="isDefault" @change="Default" color="#FF4F00" style="transform:scale(0.9)"/>
  25. </view>
  26. </view>
  27. <view class="phoneLine3" @click="delPhone" v-if="id">
  28. 删除该联系人
  29. </view>
  30. </view>
  31. <view class="submit" @click="submit">保存</view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. name:'',
  40. phone:'',
  41. id:'',
  42. isDefault:true,
  43. item:'',
  44. isDefaultNum:0,
  45. }
  46. },
  47. onLoad(opt) {
  48. //console.log(opt)
  49. this.item=JSON.parse(opt.item)
  50. console.log(this.item)
  51. if(this.item){
  52. this.name=this.item.name;
  53. this.phone=this.item.phone;
  54. this.id=this.item.id;
  55. if(this.item.isDefault==1){
  56. this.isDefault=true
  57. }else{
  58. this.isDefault=false
  59. }
  60. }
  61. },
  62. onShow() {
  63. },
  64. methods: {
  65. Default(e){
  66. //console.log(e)
  67. this.isDefault=e.detail.value
  68. console.log(this.isDefault)
  69. },
  70. delPhone(){
  71. var that=this;
  72. uni.showModal({
  73. title: '提示',
  74. content: '确定要删除联系人吗',
  75. success: function (res) {
  76. if (res.confirm) {
  77. uni.showLoading({
  78. title: '删除中'
  79. })
  80. that.$http('worldKeepCar/keepCarMy/deleteTMemberContact', {
  81. id:that.id
  82. },'POST').then(res => {
  83. uni.hideLoading();
  84. if(res.code==0){
  85. uni.navigateBack({
  86. delta:1
  87. })
  88. }
  89. })
  90. } else if (res.cancel) {
  91. }
  92. }
  93. });
  94. },
  95. submit(){
  96. uni.showLoading({
  97. title: '保存中'
  98. })
  99. var isDefault=0;
  100. if(this.name==''){
  101. uni.showToast({
  102. title: '请输入姓名',
  103. icon:"none",
  104. duration: 2000
  105. });
  106. return false;
  107. }else if(this.phone.length !=11){
  108. uni.showToast({
  109. title: '请输入正确手机号',
  110. icon:"none",
  111. duration: 2000
  112. });
  113. return false;
  114. }
  115. if(this.isDefault){
  116. this.isDefaultNum=1;
  117. }
  118. if(this.id){
  119. this.edit()
  120. }else{
  121. this.add()
  122. }
  123. },
  124. add(){
  125. this.$http('worldKeepCar/keepCarMy/addOrEditTMemberContact', {
  126. name:this.name,
  127. phone:this.phone,
  128. isDefault:this.isDefaultNum,
  129. },'POST').then(res => {
  130. uni.hideLoading();
  131. if(res.code!=0){
  132. uni.showModal({
  133. title: '提示',
  134. content: res.msg,
  135. success: function (res) {
  136. }
  137. })
  138. }else{
  139. uni.navigateBack({
  140. delta:1
  141. })
  142. }
  143. })
  144. },
  145. edit(){
  146. this.$http('worldKeepCar/keepCarMy/addOrEditTMemberContact', {
  147. name:this.name,
  148. phone:this.phone,
  149. isDefault:this.isDefaultNum,
  150. id:this.id,
  151. },'POST').then(res => {
  152. uni.hideLoading();
  153. if(res.code!=0){
  154. uni.showModal({
  155. title: '提示',
  156. content: res.msg,
  157. success: function (res) {
  158. }
  159. })
  160. }else{
  161. uni.navigateBack({
  162. delta:1
  163. })
  164. }
  165. })
  166. },
  167. login(){
  168. uni.navigateTo({
  169. url:'../login/login'
  170. })
  171. }
  172. }
  173. }
  174. </script>
  175. <style scoped>
  176. .box{
  177. min-height: 100vh;
  178. background:#F4F5F7 ;
  179. }
  180. .main{
  181. padding: 24rpx;
  182. }
  183. .phoneListBox{
  184. background: #FFFFFF;
  185. border-radius: 10rpx;
  186. padding: 0 24rpx;
  187. }
  188. .phoneLine{
  189. display: flex;
  190. padding: 30rpx;
  191. border-bottom: 1px #EEEEEE solid;
  192. }
  193. .phoneLeft{
  194. width: 150rpx;font-size: 28rpx;
  195. color: #3C3C3C;
  196. }
  197. .phoneLine2{
  198. padding:20rpx 30rpx;border-bottom: 1px solid #EEEEEE;
  199. }
  200. .lineInput{
  201. color: #333333;
  202. font-size: 28rpx;
  203. }
  204. .DefaultTxt{
  205. font-size: 28rpx;
  206. color: #3C3C3C;
  207. display: flex;
  208. align-items: center;
  209. }
  210. .submit{
  211. width: 690rpx;
  212. height: 74rpx;
  213. background: linear-gradient(124deg, #FF8700 0%, #FF4F00 100%);
  214. border-radius: 37rpx;
  215. line-height: 74rpx;
  216. text-align: center;
  217. color: #FFFFFF;
  218. font-size: 30rpx;
  219. margin-top: 80rpx;
  220. margin-left: 6rpx;
  221. }
  222. .phoneLine3{
  223. color: #FF3B30;
  224. font-size: 26rpx;
  225. padding: 30rpx;
  226. }
  227. </style>