peopleList.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. let that
  42. // import peopelInfo from "../components/peopleInfo.vue"
  43. export default {
  44. data() {
  45. return {
  46. // 选择列表
  47. peopelList: false,
  48. //出行人表单显示隐藏
  49. peopelInfoShow: 1,
  50. // 出行人选择
  51. checkboxValue1: [],
  52. // 出行人列表
  53. checkboxList: [
  54. // {name: '吴某某',disabled: false,number:"1568945752"},
  55. // {name: '吴某某',disabled: false,number:"1568945752"},
  56. ],
  57. value: 0,
  58. getpeopleList: [],
  59. defaultIndex: ''
  60. }
  61. },
  62. components: {
  63. // peopelInfo
  64. },
  65. onLoad(options) {
  66. that = this
  67. // console.log(options)
  68. if (options.id == 0) {
  69. this.peopelList = false
  70. } else {
  71. this.peopelList = true
  72. }
  73. // this.init()
  74. setTimeout(() => {
  75. if (options.obj) {
  76. let obj = JSON.parse(options.obj)
  77. this.value = obj.value
  78. this.$store.commit("getvalue", obj.value)
  79. if (obj.list.length > 0) {
  80. this.checkboxList = obj.list
  81. }
  82. }
  83. }, 500)
  84. },
  85. onShow() {
  86. that = this
  87. let token = uni.getStorageSync("token")
  88. if (!token) {
  89. //未登录
  90. uni.showToast({
  91. title: "请先登录",
  92. icon: 'none'
  93. })
  94. setTimeout(() => {
  95. uni.navigateTo({
  96. url: "/pages/login"
  97. })
  98. }, 1500)
  99. return false
  100. }
  101. this.init()
  102. this.initvist()
  103. },
  104. methods: {
  105. initvist() {
  106. let curPage = getCurrentPages();
  107. let route = curPage[curPage.length - 1].route; //获取当前页面的路由
  108. let code = uni.getStorageSync("code")
  109. let obj = {
  110. page: route,
  111. code: code
  112. }
  113. if (code) {
  114. uni.$u.http.post('/api/visit/add', obj, {
  115. custom: {
  116. auth: true
  117. }
  118. }).then((res) => {}).catch((err) => {})
  119. }
  120. },
  121. init() {
  122. this.value = this.$store.state.value
  123. uni.showLoading({
  124. title: '加载中'
  125. });
  126. uni.$u.http.post('/api/traveler/list', {
  127. custom: {
  128. auth: true
  129. }
  130. }).then((res) => {
  131. // console.log(res)
  132. let checkedlist = this.$store.state.peopleList
  133. if (checkedlist.length > 0) {
  134. let list = res
  135. checkedlist.forEach(item => {
  136. list.forEach(i => {
  137. if (item.checked && item.id == i.id) {
  138. item.checked = true
  139. } else {
  140. item.checked = false
  141. }
  142. })
  143. })
  144. this.checkboxList = list
  145. } else {
  146. this.checkboxList = res
  147. // this.$store.commit("getlist",res)
  148. let nawarr = this.checkboxList
  149. nawarr.forEach(item => {
  150. item.checked = false
  151. item.default = false
  152. })
  153. this.checkboxList = nawarr
  154. }
  155. console.log(this.checkboxList, 88888888888888)
  156. uni.hideLoading();
  157. }).catch((err) => {
  158. console.log(err)
  159. })
  160. },
  161. // // 选择
  162. // checkboxChange(e) {
  163. // console.log('change', e);
  164. // },
  165. // 选择
  166. checkbox(index) {
  167. let data = this.checkboxList
  168. if (data[index].checked) {
  169. data[index].checked = false;
  170. } else {
  171. data[index].checked = true;
  172. }
  173. this.checkboxList = JSON.parse(JSON.stringify(data))
  174. let newarr = this.checkboxList
  175. let arr = []
  176. newarr.forEach(item => {
  177. if (item.checked) {
  178. arr.push(item)
  179. }
  180. })
  181. this.getpeopleList = arr
  182. console.log(this.getpeopleList, this.value)
  183. if (this.getpeopleList.length == this.value) {
  184. // this.$toast('只能选择' + this.value + '人')
  185. this.checkboxList.forEach(item => {
  186. if (!item.checked) {
  187. item.default = true
  188. }
  189. })
  190. console.log(this.checkboxList, 5555)
  191. } else {
  192. this.checkboxList.forEach(item => {
  193. item.default = false
  194. })
  195. }
  196. this.$store.commit('getpeopleList', this.checkboxList)
  197. this.$store.commit("getopenpeopleList", 1)
  198. },
  199. // 确定添加联系人
  200. surePeople() {
  201. uni.navigateBack({
  202. delta: 1
  203. });
  204. },
  205. // 查看出行人
  206. edit(item) {
  207. let info = JSON.stringify(item)
  208. uni.navigateTo({
  209. url: `/pages/peopleList/addPeople?info=${info}&state=0`
  210. })
  211. },
  212. // 删除出行人
  213. dele(id) {
  214. uni.showModal({
  215. title: "提示",
  216. content: "确认删除吗?",
  217. success: (res) => {
  218. if (res.confirm) {
  219. this.$showLoadding("删除中")
  220. uni.$u.http.post('/api/traveler/delete', {
  221. id
  222. }, {
  223. custom: {
  224. auth: true
  225. }
  226. }).then((res) => {
  227. uni.hideLoading()
  228. that.init()
  229. setTimeout(() => {
  230. this.$toast("删除成功")
  231. }, 500)
  232. }).catch((err) => {
  233. console.log(err)
  234. })
  235. } else if (res.cancel) {
  236. console.log('用户点击取消');
  237. }
  238. }
  239. })
  240. },
  241. // 添加出行人
  242. addpeople() {
  243. uni.navigateTo({
  244. url: "/pages/peopleList/addPeople?state=1"
  245. })
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="scss">
  251. .u-cell__body--large.data-v-913eaa32 {
  252. padding: 48rpx 0 !important;
  253. box-sizing: border-box;
  254. }
  255. page {
  256. font-size: 32rpx;
  257. }
  258. .list {
  259. // margin: 50rpx 30rpx;
  260. .list-item {
  261. display: flex;
  262. justify-content: space-between;
  263. align-items: center;
  264. image {
  265. width: 36rpx;
  266. height: 36rpx;
  267. margin-bottom: 0;
  268. }
  269. border-top: 1rpx solid #E3E3E3;
  270. padding: 30rpx;
  271. &:first-child {
  272. border-top: none
  273. }
  274. }
  275. }
  276. .navbar {
  277. width: 100%;
  278. height: 104rpx;
  279. line-height: 104rpx;
  280. display: flex;
  281. border-top: 1rpx solid #E3E3E3;
  282. position: fixed;
  283. left: 0;
  284. bottom: 0;
  285. .navbar-item {
  286. // width: 50%;
  287. flex: 1;
  288. text-align: center;
  289. }
  290. .sure {
  291. background: #1E9F6A;
  292. border-radius: 0px 16rpx 0px 0px;
  293. color: #FFFFFF;
  294. }
  295. }
  296. </style>