addphone.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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="请输入" 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="请输入" 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.7)"/>
  25. </view>
  26. </view>
  27. <view class="phoneLine3" @click="delPhone">
  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. that.$http('miniAppMyBMemberCar/deleteBMemberContact', {
  79. id:that.id
  80. },'POST').then(res => {
  81. uni.hideLoading();
  82. if(res.code==0){
  83. uni.navigateBack({
  84. delta:1
  85. })
  86. }
  87. })
  88. } else if (res.cancel) {
  89. }
  90. }
  91. });
  92. },
  93. submit(){
  94. uni.showLoading({ });
  95. var isDefault=0;
  96. if(this.name==''){
  97. uni.showToast({
  98. title: '请输入姓名',
  99. icon:"none",
  100. duration: 2000
  101. });
  102. return false;
  103. }else if(this.phone.length !=11){
  104. uni.showToast({
  105. title: '请输入正确手机号',
  106. icon:"none",
  107. duration: 2000
  108. });
  109. return false;
  110. }
  111. if(this.isDefault){
  112. this.isDefaultNum=1;
  113. }
  114. if(this.id){
  115. this.edit()
  116. }else{
  117. this.add()
  118. }
  119. },
  120. add(){
  121. this.$http('miniAppMyBMemberCar/addOrEditBMemberContact', {
  122. name:this.name,
  123. phone:this.phone,
  124. isDefault:this.isDefaultNum,
  125. },'POST').then(res => {
  126. uni.hideLoading();
  127. if(res.code!=0){
  128. uni.showModal({
  129. title: '提示',
  130. content: res.msg,
  131. success: function (res) {
  132. }
  133. })
  134. }else{
  135. uni.navigateBack({
  136. delta:1
  137. })
  138. }
  139. })
  140. },
  141. edit(){
  142. this.$http('miniAppMyBMemberCar/addOrEditBMemberContact', {
  143. name:this.name,
  144. phone:this.phone,
  145. isDefault:this.isDefaultNum,
  146. id:this.id,
  147. },'POST').then(res => {
  148. uni.hideLoading();
  149. if(res.code!=0){
  150. uni.showModal({
  151. title: '提示',
  152. content: res.msg,
  153. success: function (res) {
  154. }
  155. })
  156. }else{
  157. uni.navigateBack({
  158. delta:1
  159. })
  160. }
  161. })
  162. },
  163. getList(){
  164. uni.showLoading({ });
  165. this.$http('miniAppMyBMemberCar/listBMemberContactPage', {
  166. page:this.page,
  167. limit:10,
  168. },'GET').then(res => {
  169. uni.hideLoading();
  170. var a=res.data.Items
  171. this.phoneList=this.phoneList.concat(a);
  172. })
  173. },
  174. login(){
  175. uni.navigateTo({
  176. url:'../login/login'
  177. })
  178. }
  179. }
  180. }
  181. </script>
  182. <style scoped>
  183. .box{
  184. min-height: 100vh;
  185. background:#F4F5F7 ;
  186. }
  187. .main{
  188. padding: 24rpx;
  189. }
  190. .phoneListBox{
  191. background: #FFFFFF;
  192. border-radius: 10rpx;
  193. padding: 0 24rpx;
  194. }
  195. .phoneLine{
  196. display: flex;
  197. padding: 30rpx;
  198. border-bottom: 1px solid #DDDDDD;
  199. }
  200. .phoneLeft{
  201. width: 150rpx;font-size: 28rpx;
  202. color: #3C3C3C;
  203. }
  204. .phoneLine2{
  205. padding:20rpx 30rpx;border-bottom: 1px solid #DDDDDD;
  206. }
  207. .lineInput{
  208. color: #999999;
  209. font-size: 28rpx;
  210. }
  211. .DefaultTxt{
  212. font-size: 28rpx;
  213. color: #3C3C3C;
  214. display: flex;
  215. align-items: center;
  216. }
  217. .submit{
  218. width: 690rpx;
  219. height: 74rpx;
  220. background: linear-gradient(124deg, #FF8700 0%, #FF4F00 100%);
  221. border-radius: 37rpx;
  222. line-height: 74rpx;
  223. text-align: center;
  224. color: #FFFFFF;
  225. font-size: 30rpx;
  226. margin-top: 80rpx;
  227. margin-left: 6rpx;
  228. }
  229. .phoneLine3{
  230. color: #FF3B30;
  231. font-size: 26rpx;
  232. padding: 30rpx;
  233. }
  234. </style>