choose.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="content">
  3. <view class="top-box">
  4. <view class="box-item" v-for="(item,index) in list" :key="index" @click="choose(item)">
  5. <image :src="item.avatar" mode=""></image>
  6. <text>{{item.name}}</text>
  7. </view>
  8. </view>
  9. <!-- <view class="under-box">
  10. <view class="btn">
  11. 确认
  12. </view>
  13. </view> -->
  14. <van-dialog use-slot title="自定义" :show="showDialog" show-cancel-button="true" @close="showDialog=false"
  15. @confirm="confirm">
  16. <van-field class="chageName" :value="nameValue" :focus="true" placeholder="请输入"
  17. @change="nameValue = $event.detail" />
  18. </van-dialog>
  19. </view>
  20. </template>
  21. <script>
  22. import {
  23. mapGetters
  24. } from "vuex";
  25. import * as infoApi from '@/api/sleep/equ.js';
  26. export default {
  27. data() {
  28. return {
  29. // list: [{
  30. // src: '/pages/users/static/choose1.png',
  31. // name: '爸爸',
  32. // value: 1
  33. // }, {
  34. // src: '/pages/users/static/choose2.png',
  35. // name: '妈妈',
  36. // value: 2
  37. // }, {
  38. // src: '/pages/users/static/choose3.png',
  39. // name: '儿子',
  40. // value: 3
  41. // }, {
  42. // src: '/pages/users/static/choose4.png',
  43. // name: '女儿',
  44. // value: 4
  45. // }, {
  46. // src: '/pages/users/static/choose5.png',
  47. // name: '爷爷',
  48. // value: 5
  49. // }, {
  50. // src: '/pages/users/static/choose6.png',
  51. // name: '奶奶',
  52. // value: 6
  53. // }, {
  54. // src: '/pages/users/static/choose7.png',
  55. // name: '姥爷',
  56. // value: 7
  57. // }, {
  58. // src: '/pages/users/static/choose8.png',
  59. // name: '姥姥',
  60. // value: 8
  61. // },
  62. // {
  63. // src: '/pages/users/static/vip04.png',
  64. // name: '自定义',
  65. // value: 9,
  66. // id: 99
  67. // },
  68. // ],
  69. list: [],
  70. showDialog: false,
  71. nameValue: '',
  72. }
  73. },
  74. computed: mapGetters(['uid']),
  75. onLoad() {
  76. this.getList()
  77. },
  78. methods: {
  79. getList() {
  80. infoApi.getDetailList().then(res => {
  81. let obj = {
  82. name: '自定义',
  83. avatar: 'https://employmenter.oss-cn-beijing.aliyuncs.com/%E9%80%89%E6%8B%A9%E5%85%B3%E7%B3%BB_slices/%E7%BC%96%E7%BB%84%2013%402x.png',
  84. id: 99
  85. }
  86. this.list = [...res.data, obj]
  87. })
  88. },
  89. confirm() {
  90. console.log(this.nameValue, 777);
  91. if (this.nameValue) {
  92. infoApi.createRelation({
  93. name: this.nameValue,
  94. memberId: this.uid
  95. }).then(res => {
  96. if (res.code === 0) {
  97. const item = {
  98. name: this.nameValue,
  99. id: res.data
  100. }
  101. this.goBack(item)
  102. }
  103. })
  104. .catch(err => {
  105. // close();
  106. return this.$util.Tips({
  107. title: err
  108. });
  109. });
  110. }
  111. },
  112. goBack(item) {
  113. // 1. 获取当前页面栈实例(此时最后一个元素为当前页)
  114. let pages = getCurrentPages()
  115. // 2. 上一页面实例
  116. // 注意是length长度,所以要想得到上一页面的实例需要 -2
  117. // 若要返回上上页面的实例就 -3,以此类推
  118. let prevPage = pages[pages.length - 2]
  119. // 3. 给上一页面实例绑定getValue()方法和参数(注意是$vm)
  120. prevPage.$vm.getValue(item)
  121. uni.navigateBack({
  122. delta: 1
  123. })
  124. },
  125. choose(item) {
  126. if (item.id == 99) {
  127. this.showDialog = true
  128. } else {
  129. this.goBack(item)
  130. }
  131. },
  132. },
  133. }
  134. </script>
  135. <style lang="scss">
  136. .content {
  137. position: relative;
  138. .top-box {
  139. padding: 61rpx 89rpx 0;
  140. width: 100%;
  141. height: auto;
  142. display: flex;
  143. flex-wrap: wrap;
  144. justify-content: space-between;
  145. box-sizing: border-box;
  146. .box-item {
  147. width: 30%;
  148. display: flex;
  149. flex-direction: column;
  150. align-items: center;
  151. justify-content: center;
  152. margin-top: 55rpx;
  153. image {
  154. width: 118rpx;
  155. height: 118rpx;
  156. }
  157. text {
  158. font-size: 32rpx;
  159. font-weight: 400;
  160. color: #000000;
  161. margin-top: 16rpx;
  162. }
  163. }
  164. }
  165. .under-box {
  166. width: 100%;
  167. position: fixed;
  168. bottom: 0;
  169. padding: 32rpx;
  170. box-sizing: border-box;
  171. .btn {
  172. width: 100%;
  173. height: 98rpx;
  174. line-height: 98rpx;
  175. font-size: 32rpx;
  176. font-weight: 500;
  177. color: #FFFFFF;
  178. text-align: center;
  179. border-radius: 9rpx;
  180. background-color: #F35546;
  181. }
  182. }
  183. }
  184. </style>