list.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="list u-p-b-20 u-p-l-20 u-p-r-20" ref="tableRef">
  3. <view class="list-box">
  4. <u-swipe-action :show="item.show" :index="index" v-for="(item, index) in list" :key="index"
  5. @click="actionClick" @open="open" :options="options" :btnWidth="160" class="u-m-t-20">
  6. <view class="item" @tap.stop="goDetail(item)">
  7. <u-checkbox v-if="showCheckbox" @change="checkboxChange($event,item,index)" v-model="item.checked"
  8. class="checkbox" @tap.stop shape="circle"></u-checkbox>
  9. <view class="item-cell" v-for="(column,i) in columnList" :key="i">
  10. <template v-if="column.jnpfKey != 'table'">
  11. <text class="item-cell-label">{{column.label}}:</text>
  12. <text class="item-cell-content" v-if="['calculate','inputNumber'].includes(column.jnpfKey)">
  13. {{toThousands(item[column.prop],column)}}
  14. </text>
  15. <text class="item-cell-content text-primary" v-else-if="column.jnpfKey == 'relationForm'"
  16. @click.stop="relationFormClick(item,column)">
  17. {{item[column.prop]}}
  18. </text>
  19. <view class="item-cell-content" v-else-if="column.jnpfKey == 'sign'">
  20. <JnpfSign v-model="item[column.prop]" align="left" detailed />
  21. </view>
  22. <view class="item-cell-content" v-else-if="column.jnpfKey == 'signature'">
  23. <JnpfSignature v-model="item[column.prop]" align="left" detailed />
  24. </view>
  25. <view class="item-cell-content" v-else-if="column.jnpfKey == 'uploadImg'" @click.stop>
  26. <JnpfUploadImg v-model="item[column.prop]" detailed simple
  27. v-if="item[column.prop]&&item[column.prop].length" />
  28. </view>
  29. <!-- #ifndef APP-HARMONY -->
  30. <view class="item-cell-content" v-else-if="column.jnpfKey == 'uploadFile'" @click.stop>
  31. <JnpfUploadFile v-model="item[column.prop]" detailed
  32. v-if="item[column.prop]&&item[column.prop].length" align="left" />
  33. </view>
  34. <!-- #endif -->
  35. <view class="item-cell-content" v-else-if="column.jnpfKey == 'rate'">
  36. <JnpfRate v-model="item[column.prop]" :max="column.count" :allowHalf="column.allowHalf"
  37. disabled />
  38. </view>
  39. <view class="item-cell-content item-cell-slider" v-else-if="column.jnpfKey == 'slider'">
  40. <JnpfSlider v-model="item[column.prop]" :min="column.min" :max="column.max"
  41. :step="column.step" disabled />
  42. </view>
  43. <view class="item-cell-content" v-else-if="column.jnpfKey == 'input'">
  44. <JnpfInput v-model="item[column.prop]" detailed showOverflow :useMask="column.useMask"
  45. :maskConfig="column.maskConfig" align='left' />
  46. </view>
  47. <text class="item-cell-content" v-else>{{item[column.prop]}}</text>
  48. </template>
  49. <tableCell v-else @click.stop class="tableCell" ref="tableCell" :label="column.label"
  50. :childList="item[column.prop]" :children="column.children" :pageLen="3"
  51. @cRelationForm="relationFormClick">
  52. </tableCell>
  53. </view>
  54. <view class="item-cell" v-if="config.enableFlow==1">
  55. <text class="item-cell-label">审批状态:</text>
  56. <text :style="{color:useDefine.getFlowStatusColor(item.flowState)}">
  57. {{useDefine.getFlowStatusContent(item.flowState)}}
  58. </text>
  59. </view>
  60. </view>
  61. </u-swipe-action>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import {
  67. useDefineSetting
  68. } from '@/utils/useDefineSetting';
  69. import tableCell from '../tableCell.vue'
  70. export default {
  71. emits: ['selectCheckbox', 'handleClick', 'handleMoreClick', 'goDetail', 'relationFormClick', 'update:modelValue'],
  72. components: {
  73. tableCell
  74. },
  75. props: ['config', 'list', 'columnList', 'actionOptions', 'showSelect', 'checkedAll', 'modelValue', 'isMoreBtn',
  76. 'customBtnsList'
  77. ],
  78. data() {
  79. return {
  80. selectData: [],
  81. useDefine: useDefineSetting()
  82. }
  83. },
  84. watch: {
  85. checkedAll: {
  86. handler(val) {
  87. this.handleCheckAll()
  88. },
  89. immediate: true
  90. }
  91. },
  92. computed: {
  93. options() {
  94. if (!this.customBtnsList?.length) return this.actionOptions;
  95. return [{
  96. text: this.$t('common.moreText'),
  97. value: 'more',
  98. style: {
  99. backgroundColor: '#007aff'
  100. }
  101. },
  102. ...this.actionOptions,
  103. ];
  104. },
  105. showCheckbox() {
  106. return this.showSelect
  107. }
  108. },
  109. methods: {
  110. open(index) {
  111. this.list[index].show = true;
  112. this.list.map((val, idx) => {
  113. if (index != idx) this.list[idx].show = false;
  114. })
  115. },
  116. /* 关联表单操作 */
  117. relationFormClick(item, column) {
  118. this.$emit('relationFormClick', item, column)
  119. },
  120. /* 跳转详情 */
  121. goDetail(item) {
  122. this.$emit('goDetail', item)
  123. },
  124. actionClick(itemIndex, btnIndex) {
  125. if (this.options[btnIndex].value === 'remove') return this.$emit('handleClick', itemIndex)
  126. if (this.options[btnIndex].value === 'more') return this.$emit('handleMoreClick', itemIndex)
  127. },
  128. /* 列表选择框 */
  129. checkboxChange(e, item) {
  130. const isSelected = e.value;
  131. const itemIndex = this.list.indexOf(item);
  132. if (itemIndex === -1) return;
  133. const selectedItemsSet = new Set(this.selectData.map(selectedItem => {
  134. return selectedItem.id;
  135. }));
  136. if (isSelected) {
  137. selectedItemsSet.add(item.id);
  138. } else {
  139. selectedItemsSet.delete(item.id);
  140. }
  141. this.selectData = [...selectedItemsSet.values()].map(id => {
  142. return this.list.find(listItem => listItem.id === id);
  143. });
  144. this.$emit('selectCheckbox', this.selectData);
  145. },
  146. /* 全部选中 */
  147. handleCheckAll() {
  148. this.selectData = []
  149. if (this.checkedAll) this.selectData = this.list.filter(o => o.checked)
  150. this.$emit('selectCheckbox', this.selectData)
  151. },
  152. /* 千分位操作 */
  153. toThousands(val, column) {
  154. if (val) {
  155. let valList = val.toString().split('.')
  156. let num = Number(valList[0])
  157. let newVal = column.thousands ? num.toLocaleString() : num
  158. return valList[1] ? newVal + '.' + valList[1] : newVal
  159. } else {
  160. return val
  161. }
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss">
  167. .item {
  168. padding: 0 !important;
  169. .checkbox {
  170. position: absolute;
  171. top: 6rpx;
  172. left: 8rpx;
  173. z-index: 9999;
  174. }
  175. }
  176. .right-option-box {
  177. display: flex;
  178. width: max-content;
  179. .right-option {
  180. width: 144rpx;
  181. height: 100%;
  182. font-size: 16px;
  183. color: #fff;
  184. background-color: #dd524d;
  185. display: flex;
  186. align-items: center;
  187. justify-content: center;
  188. }
  189. .more-option {
  190. background-color: #1890ff;
  191. }
  192. }
  193. </style>