GetRelationContract.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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.$util.getState(this,"projectCode");
  55. let searchValue = this.searchVal;
  56. uni.showLoading({
  57. title: "页面努力加载中,请稍候...",
  58. mask: true
  59. });
  60. console.info("projectCode",projectCode);
  61. if(this.$util.isEmpty(projectCode)){
  62. uni.showToast({
  63. title:'项目编号丢失,请重新登录',
  64. duration:4000,
  65. icon:'none'
  66. });
  67. return;
  68. }
  69. GetRelationContract(projectCode, searchValue).then((res) => {
  70. uni.hideLoading();
  71. console.info('getcontractList');
  72. //console.info(projectCode);
  73. console.info(res);
  74. //return;
  75. res.forEach(function(item, index, array) {
  76. that.$set(that.contractList, index, item);
  77. });
  78. //console.info(that.contractList);
  79. });
  80. },
  81. checkboxChange: function(e) {
  82. var items = this.contractList,
  83. values = e.detail.value;
  84. this.checkboxValues = values.join(',');
  85. console.info("values");
  86. console.info(values);
  87. console.info(this.checkboxValues);
  88. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  89. const item = items[i]
  90. if (values.includes(item.value)) {
  91. this.$set(item, 'checked', true)
  92. } else {
  93. this.$set(item, 'checked', false)
  94. }
  95. }
  96. },
  97. submitForm(e) {
  98. console.info(this.checkboxValues);
  99. //先记录值,下面this指向会不一样
  100. let relationContractCodes = this.checkboxValues;
  101. let arr=relationContractCodes.split(',');
  102. let selectChecked=[];
  103. this.contractList.forEach(function(item,index,array){
  104. arr.forEach(function(item1,index1,array1){
  105. if(item.contractCode==item1){
  106. selectChecked.push({contractCode:item.contractCode,contractID:item.contractID,contractName:item.contractName,estimateCash:0.00});
  107. }
  108. });
  109. });
  110. //将数据发射到父级监听事件中
  111. uni.$emit('fire', selectChecked);
  112. //关闭当前窗口
  113. uni.navigateBack({});
  114. },
  115. search(res) { //回车搜索
  116. this.searchvalue = res.value; //赋值
  117. this.contractList=[];
  118. this.getcontractList(); //调用搜索方法
  119. },
  120. input(res) {
  121. this.searchVal = res.value
  122. },
  123. cancel(res) {
  124. console.info('点击取消,输入值为:' + res.value);
  125. },
  126. }
  127. }
  128. </script>
  129. <style scoped>
  130. .slot-box {
  131. margin: 5px 5px;
  132. }
  133. .uni-btn-v {
  134. position: fixed;
  135. bottom: 0;
  136. width: 100%;
  137. }
  138. uni-view{
  139. font-size:15px;
  140. }
  141. </style>