choose.vue 4.5 KB

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