choose.vue 4.4 KB

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