e03038437a613f366fb834b95ac0317650b7a53a.svn-base 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="components-input-demo-presuffix" v-if="avalid">
  3. <!---->
  4. <a-input @click="openModal" :placeholder="placeholder" v-model="showText" readOnly :disabled="disabled">
  5. <a-icon slot="prefix" type="cluster" :title="title"/>
  6. <a-icon v-if="showText" slot="suffix" type="close-circle" @click="handleEmpty" title="清空"/>
  7. </a-input>
  8. <j-popup-onl-report
  9. ref="jPopupOnlReport"
  10. :code="code"
  11. :multi="multi"
  12. :sorter="sorter"
  13. :groupId="uniqGroupId"
  14. :param="param"
  15. @ok="callBack"
  16. />
  17. </div>
  18. </template>
  19. <script>
  20. import JPopupOnlReport from './modal/JPopupOnlReport'
  21. export default {
  22. name: 'JPopup',
  23. components: {
  24. JPopupOnlReport
  25. },
  26. props: {
  27. code: {
  28. type: String,
  29. default: '',
  30. required: false
  31. },
  32. field: {
  33. type: String,
  34. default: '',
  35. required: false
  36. },
  37. orgFields: {
  38. type: String,
  39. default: '',
  40. required: false
  41. },
  42. destFields: {
  43. type: String,
  44. default: '',
  45. required: false
  46. },
  47. /** 排序列,指定要排序的列,使用方式:列名=desc|asc */
  48. sorter: {
  49. type: String,
  50. default: ''
  51. },
  52. width: {
  53. type: Number,
  54. default: 1200,
  55. required: false
  56. },
  57. placeholder: {
  58. type: String,
  59. default: '请选择',
  60. required: false
  61. },
  62. value: {
  63. type: String,
  64. required: false
  65. },
  66. triggerChange: {
  67. type: Boolean,
  68. required: false,
  69. default: false
  70. },
  71. disabled: {
  72. type: Boolean,
  73. required: false,
  74. default: false
  75. },
  76. multi: {
  77. type: Boolean,
  78. required: false,
  79. default: false
  80. },
  81. //popup动态参数 支持系统变量语法
  82. param:{
  83. type: Object,
  84. required: false,
  85. default: ()=>{}
  86. },
  87. spliter:{
  88. type: String,
  89. required: false,
  90. default: ','
  91. },
  92. /** 分组ID,用于将多个popup的请求合并到一起,不传不分组 */
  93. groupId: String
  94. },
  95. data() {
  96. return {
  97. showText: '',
  98. title: '',
  99. avalid: true
  100. }
  101. },
  102. computed: {
  103. uniqGroupId() {
  104. if (this.groupId) {
  105. let { groupId, code, field, orgFields, destFields } = this
  106. return `${groupId}_${code}_${field}_${orgFields}_${destFields}`
  107. }
  108. }
  109. },
  110. watch: {
  111. value: {
  112. immediate: true,
  113. handler: function(val) {
  114. if (!val) {
  115. this.showText = ''
  116. } else {
  117. this.showText = val.split(this.spliter).join(',')
  118. }
  119. }
  120. }
  121. },
  122. created() {
  123. },
  124. mounted() {
  125. if (!this.orgFields || !this.destFields || !this.code) {
  126. this.$message.error('popup参数未正确配置!')
  127. this.avalid = false
  128. }
  129. if (this.destFields.split(',').length != this.orgFields.split(',').length) {
  130. this.$message.error('popup参数未正确配置,原始值和目标值数量不一致!')
  131. this.avalid = false
  132. }
  133. },
  134. methods: {
  135. openModal() {
  136. if (this.disabled === false) {
  137. this.$refs.jPopupOnlReport.show()
  138. }
  139. },
  140. handleEmpty() {
  141. // 禁用时,不允许清空内容
  142. if (this.disabled) {
  143. return
  144. }
  145. this.showText = ''
  146. let destFieldsArr = this.destFields.split(',')
  147. if (destFieldsArr.length === 0) {
  148. return
  149. }
  150. let res = {}
  151. for (let i = 0; i < destFieldsArr.length; i++) {
  152. res[destFieldsArr[i]] = ''
  153. }
  154. if (this.triggerChange) {
  155. this.$emit('callback', res)
  156. } else {
  157. this.$emit('input', '', res)
  158. }
  159. },
  160. callBack(rows) {
  161. // update--begin--autor:lvdandan-----date:20200630------for:多选时未带回多个值------
  162. let orgFieldsArr = this.orgFields.split(',')
  163. let destFieldsArr = this.destFields.split(',')
  164. let resetText = false
  165. if (this.field && this.field.length > 0) {
  166. this.showText = ''
  167. resetText = true
  168. }
  169. let res = {}
  170. if (orgFieldsArr.length > 0) {
  171. for (let i = 0; i < orgFieldsArr.length; i++) {
  172. let tempDestArr = []
  173. for(let rw of rows){
  174. let val = rw[orgFieldsArr[i]]
  175. // update--begin--autor:liusq-----date:20210713------for:处理val等于0的情况issues/I3ZL4T------
  176. if(typeof val=='undefined'|| val==null || val.toString()==""){
  177. val = ""
  178. }
  179. // update--end--autor:liusq-----date:20210713------for:处理val等于0的情况issues/I3ZL4T------
  180. tempDestArr.push(val)
  181. }
  182. res[destFieldsArr[i]] = tempDestArr.join(",")
  183. }
  184. if (resetText === true) {
  185. let tempText = []
  186. for(let rw of rows){
  187. let val = rw[orgFieldsArr[destFieldsArr.indexOf(this.field)]]
  188. if(!val){
  189. val = ""
  190. }
  191. tempText.push(val)
  192. }
  193. this.showText = tempText.join(",")
  194. }
  195. // update--end--autor:lvdandan-----date:20200630------for:多选时未带回多个值------
  196. }
  197. if (this.triggerChange) {
  198. //v-dec时即triggerChange为true时 将整个对象给form页面 让他自己setFieldsValue
  199. this.$emit('callback', res)
  200. } else {
  201. //v-model时 需要传一个参数field 表示当前这个字段 从而根据这个字段的顺序找到原始值
  202. // this.$emit("input",row[orgFieldsArr[destFieldsArr.indexOf(this.field)]])
  203. let str = ''
  204. if(this.showText){
  205. str = this.showText.split(',').join(this.spliter)
  206. }
  207. this.$emit('input', str, res)
  208. }
  209. }
  210. }
  211. }
  212. </script>
  213. <style scoped>
  214. .components-input-demo-presuffix .anticon-close-circle {
  215. cursor: pointer;
  216. color: #ccc;
  217. transition: color 0.3s;
  218. font-size: 12px;
  219. }
  220. .components-input-demo-presuffix .anticon-close-circle:hover {
  221. color: #f5222d;
  222. }
  223. .components-input-demo-presuffix .anticon-close-circle:active {
  224. color: #666;
  225. }
  226. </style>