GetRelationContract.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view>
  3. <view>
  4. <uni-search-bar :radius="100" @confirm="search" @input="input" @cancel="cancel"></uni-search-bar>
  5. </view>
  6. <uni-forms ref="form" @submit="submitForm">
  7. <uni-list>
  8. <checkbox-group @change="checkboxChange">
  9. <uni-list-item v-for="(item,index) in contractList" :key="index">
  10. <!-- 自定义 header -->
  11. <view slot="header" class="slot-box">
  12. <checkbox :value="item.contractCode" />
  13. </view>
  14. <!-- 自定义 body -->
  15. <view slot="body" class="slot-box">
  16. {{item.contractID}}
  17. </view>
  18. <!-- 自定义 footer-->
  19. <view slot="footer" class="slot-box">
  20. {{item.contractName}}
  21. </view>
  22. </uni-list-item>
  23. </checkbox-group>
  24. </uni-list>
  25. <view class="uni-btn-v uni-column">
  26. <button type="primary" form-type="submit" style="border-radius: 15px;">选择成功,确认</button>
  27. </view>
  28. </uni-forms>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. GetRelationContract
  34. } from "@/common/api/requisitionApi.js";
  35. export default {
  36. data() {
  37. return {
  38. contractList: [],
  39. checkboxValues: [],
  40. searchVal: ''
  41. }
  42. },
  43. onLoad: function() {
  44. //console.info('授权');
  45. //console.info(this.$auth);
  46. this.$util.persistLogin(this);
  47. },
  48. created: function() {
  49. this.getcontractList();
  50. },
  51. methods: {
  52. getcontractList: function() {
  53. var that = this;
  54. var projectCode = this.$store.state.projectCode;
  55. let searchValue = this.searchVal;
  56. uni.showLoading({
  57. title: "页面努力加载中,请稍候...",
  58. mask: true
  59. });
  60. GetRelationContract(projectCode, searchValue).then((res) => {
  61. uni.hideLoading();
  62. console.info('getcontractList');
  63. //console.info(projectCode);
  64. console.info(res);
  65. //return;
  66. res.forEach(function(item, index, array) {
  67. that.$set(that.contractList, index, item);
  68. });
  69. //console.info(that.contractList);
  70. });
  71. },
  72. checkboxChange: function(e) {
  73. var items = this.contractList,
  74. values = e.detail.value;
  75. this.checkboxValues = values.join(',');
  76. console.info("values");
  77. console.info(values);
  78. console.info(this.checkboxValues);
  79. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  80. const item = items[i]
  81. if (values.includes(item.value)) {
  82. this.$set(item, 'checked', true)
  83. } else {
  84. this.$set(item, 'checked', false)
  85. }
  86. }
  87. },
  88. submitForm(e) {
  89. console.info(this.checkboxValues);
  90. //先记录值,下面this指向会不一样
  91. let relationContractCodes = this.checkboxValues;
  92. let arr=relationContractCodes.split(',');
  93. let selectChecked=[];
  94. this.contractList.forEach(function(item,index,array){
  95. arr.forEach(function(item1,index1,array1){
  96. if(item.contractCode==item1){
  97. selectChecked.push({contractCode:item.contractCode,contractID:item.contractID,contractName:item.contractName,estimateCash:0.00});
  98. }
  99. });
  100. });
  101. //将数据发射到父级监听事件中
  102. uni.$emit('fire', selectChecked);
  103. //关闭当前窗口
  104. uni.navigateBack({});
  105. },
  106. search(res) { //回车搜索
  107. this.searchvalue = res.value; //赋值
  108. this.contractList=[];
  109. this.getcontractList(); //调用搜索方法
  110. },
  111. input(res) {
  112. this.searchVal = res.value
  113. },
  114. cancel(res) {
  115. console.info('点击取消,输入值为:' + res.value);
  116. }
  117. }
  118. }
  119. </script>
  120. <style scoped>
  121. .slot-box {
  122. margin: 5px 5px;
  123. }
  124. .uni-btn-v {
  125. position: fixed;
  126. bottom: 0;
  127. width: 100%;
  128. }
  129. uni-view{
  130. font-size:15px;
  131. }
  132. </style>