SelectEgineeringContract.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. <radio-group @change="radioChange">
  9. <uni-list-item v-for="(item,index) in contractList" :key="index">
  10. <!-- 自定义 header -->
  11. <view slot="header" class="slot-box-header">
  12. <radio :value="item.contractCode" />
  13. </view>
  14. <!-- 自定义 body -->
  15. <view slot="body" class="slot-box-body">
  16. {{item.contractID}}
  17. </view>
  18. <!-- 自定义 footer-->
  19. <view slot="footer" class="slot-box-footer">
  20. {{item.contractName}}
  21. </view>
  22. </uni-list-item>
  23. </radio-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. GetEngineeringContracts
  34. } from "@/common/api/commonApi.js";
  35. export default {
  36. data() {
  37. return {
  38. contractList: [],
  39. radioValue: [],
  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. let projectcode = this.$util.getState(this,'projectCode');
  55. let searchValue = this.searchVal;
  56. uni.showLoading({
  57. title: "页面努力加载中,请稍候...",
  58. mask: true
  59. });
  60. GetEngineeringContracts(projectcode, searchValue).then((res) => {
  61. uni.hideLoading();
  62. console.info('GetEngineeringContracts', res);
  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. radioChange: function(evt) {
  73. //console.info(evt);
  74. //console.info(evt.target.value);
  75. //console.info('contractList',this.contractList);
  76. for (let i = 0; i < this.contractList.length; i++) {
  77. if (this.contractList[i].contractCode === evt.target.value) {
  78. console.info(evt.target.value);
  79. this.current = i;
  80. this.radioValue = this.contractList[i];
  81. console.info('this.radioValue', this.radioValue);
  82. break;
  83. }
  84. }
  85. },
  86. submitForm(e) {
  87. console.info('submitForm',this.radioValue);
  88. //先记录值,下面this指向会不一样
  89. let relationContractCodes = this.radioValue;
  90. if (relationContractCodes.length<=0) {
  91. uni.showToast({
  92. title: '请选择合同',
  93. duration: 3000,
  94. icon: 'none'
  95. })
  96. return;
  97. }
  98. let selectChecked = [];
  99. selectChecked.push({
  100. contractCode: relationContractCodes.contractCode,
  101. contractID: relationContractCodes.contractID,
  102. contractName: relationContractCodes.contractName,
  103. supplierCode:relationContractCodes.supplierCode,
  104. supplierTypeCode:relationContractCodes.supplierTypeCode,
  105. supplierTypeId:relationContractCodes.supplierTypeId
  106. });
  107. console.info('selectChecked',selectChecked);
  108. //return;
  109. //将数据发射到父级监听事件中
  110. uni.$emit('engineeringContract', selectChecked);
  111. //关闭当前窗口
  112. uni.navigateBack();
  113. },
  114. search(res) { //回车搜索
  115. this.searchvalue = res.value; //赋值
  116. this.contractList = [];
  117. this.getcontractList(); //调用搜索方法
  118. },
  119. input(res) {
  120. this.searchVal = res.value
  121. },
  122. cancel(res) {
  123. console.info('点击取消,输入值为:' + res.value);
  124. }
  125. }
  126. }
  127. </script>
  128. <style scoped>
  129. .slot-box-header {
  130. margin: 5px 5px;
  131. width: 40px;
  132. }
  133. .slot-box-body {
  134. margin: 5px 5px;
  135. width: 180px;
  136. }
  137. .slot-box-footer {
  138. margin: 5px 5px;
  139. width: 180px;
  140. }
  141. .uni-btn-v {
  142. position: fixed;
  143. bottom: 0;
  144. width: 100%;
  145. }
  146. uni-view {
  147. font-size: 15px;
  148. }
  149. </style>