peopleList.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="addpeople">
  3. <view class="list">
  4. <!-- <u-checkbox-group v-model="checkboxValue1" placement="column" @change="checkboxChange" shape="circle" size=32> -->
  5. <view class="list-item" v-for="(item, index) in checkboxList" :key="index">
  6. <!-- <u-checkbox v-if="peopelList" iconSize=32 style="padding: 0 100rpx;" :name="item" activeColor="#1E9F6A"></u-checkbox> -->
  7. <radio v-if="peopelList" color="#1E9F6A" style="font-size: 26rpx;" :checked="item.checked"
  8. :value="index" @click="checkbox(index)" :disabled="item.default"></radio>
  9. <view class="" style="margin:0 64rpx 0 32rpx;width:100rpx;">
  10. {{item.name}}
  11. </view>
  12. <view class="">
  13. {{item.phone}}
  14. </view>
  15. <view class="image" style="flex: 1;text-align: right;align-items: center;">
  16. <text class=""
  17. style="font-size: 28rpx;color: #1E9F6A;border-right: 1rpx solid #1E9F6A;padding-right: 30rpx;margin-right: 30rpx;"
  18. @click="dele(item.id)">
  19. 删除
  20. </text>
  21. <image src="../../static/editIcon.png" mode="widthFix" @click="edit(item)"></image>
  22. <!-- <image src="../../static/editIcon.png" mode="widthFix"></image> -->
  23. </view>
  24. </view>
  25. <!-- </u-checkbox-group> -->
  26. </view>
  27. <view style="margin-top: 140rpx;">
  28. <u-loadmore v-if="checkboxList.length==0" :status="nomore" fontSize="30" :line="true" nomoreText="暂无出行人" />
  29. </view>
  30. <view class="navbar">
  31. <view class="navbar-item" @click="addpeople">
  32. + 新增出行人
  33. </view>
  34. <view class="navbar-item sure" v-if="peopelList" @click="surePeople">
  35. 确定出行人
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. // import peopelInfo from "../components/peopleInfo.vue"
  42. export default {
  43. data() {
  44. return {
  45. // 选择列表
  46. peopelList: false,
  47. //出行人表单显示隐藏
  48. peopelInfoShow: 1,
  49. // 出行人选择
  50. checkboxValue1: [],
  51. // 出行人列表
  52. checkboxList: [
  53. // {name: '吴某某',disabled: false,number:"1568945752"},
  54. // {name: '吴某某',disabled: false,number:"1568945752"},
  55. ],
  56. value: 0,
  57. getpeopleList: [],
  58. defaultIndex: ''
  59. }
  60. },
  61. components: {
  62. // peopelInfo
  63. },
  64. onLoad(options) {
  65. // console.log(options)
  66. if (options.id == 0) {
  67. this.peopelList = false
  68. } else {
  69. this.peopelList = true
  70. }
  71. this.init()
  72. setTimeout(()=>{
  73. if (options.obj) {
  74. let obj=JSON.parse(options.obj)
  75. this.value = obj.value
  76. if(obj.list.length>0){
  77. this.checkboxList=obj.list
  78. }
  79. }
  80. },500)
  81. },
  82. onShow() {
  83. let token = uni.getStorageSync("token")
  84. if (!token) {
  85. //未登录
  86. uni.showToast({
  87. title: "请先登录",
  88. icon: 'none'
  89. })
  90. setTimeout(() => {
  91. uni.navigateTo({
  92. url: "/pages/login"
  93. })
  94. }, 1500)
  95. return false
  96. }
  97. uni.showLoading({
  98. title: '加载中'
  99. });
  100. },
  101. methods: {
  102. init() {
  103. uni.$u.http.post('/api/traveler/list', {
  104. custom: {
  105. auth: true
  106. }
  107. }).then((res) => {
  108. // console.log(res)
  109. this.checkboxList = res
  110. // this.$store.commit("getlist",res)
  111. let nawarr = this.checkboxList
  112. nawarr.forEach(item => {
  113. item.checked = false
  114. item.default=false
  115. })
  116. this.checkboxList = nawarr
  117. uni.hideLoading();
  118. }).catch((err) => {
  119. console.log(err)
  120. })
  121. },
  122. // // 选择
  123. // checkboxChange(e) {
  124. // console.log('change', e);
  125. // },
  126. // 选择
  127. checkbox(index) {
  128. let data = this.checkboxList
  129. if (data[index].checked) {
  130. data[index].checked = false;
  131. } else {
  132. data[index].checked = true;
  133. }
  134. this.checkboxList = JSON.parse(JSON.stringify(data))
  135. let newarr = this.checkboxList
  136. let arr = []
  137. newarr.forEach(item => {
  138. if (item.checked) {
  139. arr.push(item)
  140. }
  141. })
  142. this.getpeopleList = arr
  143. console.log(this.getpeopleList, this.value)
  144. if (this.getpeopleList.length ==this.value) {
  145. // this.$toast('只能选择' + this.value + '人')
  146. this.checkboxList.forEach(item=>{
  147. if(!item.checked){
  148. item.default=true
  149. }
  150. })
  151. console.log(this.checkboxList,5555)
  152. }else{
  153. this.checkboxList.forEach(item=>{
  154. item.default=false
  155. })
  156. }
  157. this.$store.commit('getpeopleList', this.checkboxList)
  158. console.log(this.$store.state.openpeopleList,454)
  159. this.$store.commit("getopenpeopleList", 1)
  160. },
  161. // 确定添加联系人
  162. surePeople() {
  163. uni.navigateBack({
  164. delta: 1
  165. });
  166. },
  167. // 查看出行人
  168. edit(item) {
  169. let info = JSON.stringify(item)
  170. uni.navigateTo({
  171. url: `/pages/peopleList/addPeople?info=${info}&state=0`
  172. })
  173. },
  174. // 删除出行人
  175. dele(id) {
  176. uni.showModal({
  177. title: "提示",
  178. content: "确认删除吗?",
  179. success: (res) => {
  180. if (res.confirm) {
  181. this.$showLoadding("删除中")
  182. uni.$u.http.post('/api/traveler/delete', {
  183. id
  184. }, {
  185. custom: {
  186. auth: true
  187. }
  188. }).then((res) => {
  189. uni.hideLoading()
  190. this.$toast("删除成功")
  191. this.init()
  192. }).catch((err) => {
  193. console.log(err)
  194. })
  195. } else if (res.cancel) {
  196. console.log('用户点击取消');
  197. }
  198. }
  199. })
  200. },
  201. // 添加出行人
  202. addpeople() {
  203. uni.navigateTo({
  204. url: "/pages/peopleList/addPeople?state=1"
  205. })
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss">
  211. .u-cell__body--large.data-v-913eaa32 {
  212. padding: 48rpx 0 !important;
  213. box-sizing: border-box;
  214. }
  215. page {
  216. font-size: 32rpx;
  217. }
  218. .list {
  219. // margin: 50rpx 30rpx;
  220. .list-item {
  221. display: flex;
  222. justify-content: space-between;
  223. align-items: center;
  224. image {
  225. width: 36rpx;
  226. height: 36rpx;
  227. margin-bottom: 0;
  228. }
  229. border-top: 1rpx solid #E3E3E3;
  230. padding: 30rpx;
  231. &:first-child {
  232. border-top: none
  233. }
  234. }
  235. }
  236. .navbar {
  237. width: 100%;
  238. height: 104rpx;
  239. line-height: 104rpx;
  240. display: flex;
  241. border-top: 1rpx solid #E3E3E3;
  242. position: fixed;
  243. left: 0;
  244. bottom: 0;
  245. .navbar-item {
  246. // width: 50%;
  247. flex: 1;
  248. text-align: center;
  249. }
  250. .sure {
  251. background: #1E9F6A;
  252. border-radius: 0px 16rpx 0px 0px;
  253. color: #FFFFFF;
  254. }
  255. }
  256. </style>