UiLinkage.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <el-row class="form-group">
  3. <el-col :span="3" style="min-height:50px;padding-top:10px;">
  4. <label style="margin-left:10px;vertical-align: middle;" class="control-label">{{label ? label : 'Select'}}</label>
  5. </el-col>
  6. <!-- 一级菜单 -->
  7. <el-col :span="7">
  8. <el-select :id="one_name+'_select'" v-model="one_id" :multiple="multiple ? true : false" :disabled="disabled ? true : false"
  9. :size="size ? size : 'large'" :clearable="clearable ? true : false" :multiple-limit="multipleLimit ? multiple-limit : 0"
  10. :placeholder="placeholder ? placeholder : '请选择'" @change="selectChange(one_id,'one_name')">
  11. <el-option v-for="one_item in one_data" :key="one_item.value" :label="one_item.label" :value="one_item.value+''">
  12. <span style="float: left">{{one_item.label}}</span>
  13. <span style="float: right; color: #8492a6; font-size: 13px">{{one_item.notice?one_item.notice:one_item.value}}</span>
  14. </el-option>
  15. </el-select>
  16. <input type='text' :name="one_name?one_name:'select_one'" :id="one_name" class="ui-input-select-el-col-select"
  17. :value="one_id" style="width:0;height:0.5px;border: 0 solid rgba(255,255,255,0)">
  18. </el-col>
  19. <!-- 二级菜单 -->
  20. <el-col :span="7" v-show="one_id>0 && tier*1>=2">
  21. <el-select :id="two_name+'_select'" v-model="two_id" :multiple="multiple ? true : false" :disabled="disabled ? true : false"
  22. :size="size ? size : 'large'" :clearable="clearable ? true : false" :multiple-limit="multipleLimit ? multiple-limit : 0"
  23. :placeholder="placeholder ? placeholder : '请选择'" @change="selectChange(two_id,'two_name')">
  24. <el-option v-for="two_item in two_data" :key="two_item.value" :label="two_item.label" :value="two_item.value+''">
  25. <span style="float: left">{{two_item.label}}</span>
  26. <span style="float: right; color: #8492a6; font-size: 13px">{{two_item.notice?two_item.notice:two_item.value}}</span>
  27. </el-option>
  28. </el-select>
  29. <input type='text' :name="two_name?two_name:'select_two'" :id="two_name" class="ui-input-select-el-col-select"
  30. :value="two_id" style="width:0;height:0.5px;border: 0 solid rgba(255,255,255,0)">
  31. </el-col>
  32. <!-- 三级菜单 -->
  33. <el-col :span="7" v-show="two_id>0 && three_data.length>1 && tier*1>=3">
  34. <el-select :id="three_name+'_select'" v-model="three_id" :multiple="multiple ? true : false" :disabled="disabled ? true : false"
  35. :size="size ? size : 'large'" :clearable="clearable ? true : false" :multiple-limit="multipleLimit ? multiple-limit : 0"
  36. :placeholder="placeholder ? placeholder : '请选择'" @change="selectChange(three_id,'three_name')">
  37. <el-option v-for="three_item in three_data" :key="three_item.value" :label="three_item.label" :value="three_item.value+''">
  38. <span style="float: left">{{three_item.label}}</span>
  39. <span style="float: right; color: #8492a6; font-size: 13px">{{three_item.notice?three_item.notice:three_item.value}}</span>
  40. </el-option>
  41. </el-select>
  42. <input type='text' :name="three_name?three_name:'select_three'" :id="three_name" class="ui-input-select-el-col-select"
  43. :value="three_id" style="width:0;height:0.5px;border: 0 solid rgba(255,255,255,0)">
  44. </el-col>
  45. </el-row>
  46. </template>
  47. <script>
  48. export default {
  49. props: ['label', 'multiple', 'disabled', 'size', 'clearable', 'multipleLimit', 'name', 'placeholder', 'free', 'tips',
  50. 'options','tier_num'
  51. ],
  52. data() {
  53. return {
  54. 'tier':this._props.options.tier_num ? this._props.options.tier_num : 3,
  55. 'one_id': this._props.options.one_id ? this._props.options.one_id : '0',
  56. 'two_id': this._props.options.two_id ? this._props.options.two_id : '0',
  57. 'three_id': this._props.options.three_id ? this._props.options.three_id : '0',
  58. 'send_url': this._props.options.send_url ? this._props.options.send_url : '',
  59. 'one_name': this._props.options.one_name ? this._props.options.one_name : 'one_name',
  60. 'two_name': this._props.options.two_name ? this._props.options.two_name : 'two_name',
  61. 'three_name': this._props.options.three_name ? this._props.options.three_name : 'three_name',
  62. 'one_data': [{
  63. "value": '0',
  64. "label": "请选择",
  65. "disabled": false,
  66. "notice": "*"
  67. }],
  68. 'two_data': [{
  69. "value": '0',
  70. "label": "请选择",
  71. "disabled": false,
  72. "notice": "*"
  73. }],
  74. 'three_data': [{
  75. "value": '0',
  76. "label": "请选择",
  77. "disabled": false,
  78. "notice": "*"
  79. }],
  80. };
  81. },
  82. mounted() {
  83. if (this._props.multiple) {
  84. $(document).find('#select-ui-' + this._props.name + ' input.el-input__inner').css({
  85. color: 'rgba(255,255,255,0)'
  86. });
  87. if (this._props.options.checked) {
  88. this.setData(this._props.options.checked);
  89. }
  90. }
  91. },
  92. methods: {
  93. selectChange(value, key_name) {
  94. this.setData(value, key_name);
  95. if (key_name == 'one_name') {
  96. this.getDataList('two_name',0);
  97. this.two_data = [{
  98. "value": '0',
  99. "label": "请选择",
  100. "disabled": false,
  101. "notice": "*"
  102. }];
  103. this.two_id = 0
  104. } else if (key_name == 'two_name') {
  105. this.getDataList('three_name',0);
  106. this.three_data = [{
  107. "value": '0',
  108. "label": "请选择",
  109. "disabled": false,
  110. "notice": "*"
  111. }];
  112. this.three_id = 0
  113. }
  114. },
  115. setData(value, key_name) {
  116. var select_name = this._props[key_name];
  117. this.$emit('set-keys',value,key_name);
  118. console.log('选择值:' + value);
  119. console.log('触发值:' + value);
  120. $(document).find('input#' + select_name).val(value+'');
  121. $(document).find('input#' + select_name ).trigger("change");
  122. if (key_name == 'one_name') {
  123. this.one_id = value;
  124. } else if (key_name == 'two_name') {
  125. this.two_id = value;
  126. }else{
  127. this.three_id = value;
  128. }
  129. },
  130. getDataList(key_name,select_id) {
  131. var p_id = 0;
  132. if (key_name == 'two_name') {
  133. p_id = this.one_id;
  134. if(p_id*1<=0)return false;
  135. } else if (key_name == 'three_name') {
  136. p_id = this.two_id;
  137. if(p_id*1<=0)return false;
  138. }
  139. var linkage_vue = this;
  140. $.ajax({
  141. type: 'post',
  142. url: this.send_url,
  143. data: {
  144. 'p_id': p_id,
  145. 'select_id': select_id
  146. },
  147. dataType: 'json',
  148. success: function(msg) {
  149. if (msg.status * 1 == 1) {
  150. if (key_name == 'two_name') {
  151. linkage_vue.two_data = msg.data;
  152. } else if (key_name == 'three_name') {
  153. linkage_vue.three_data = msg.data;
  154. } else {
  155. linkage_vue.one_data = msg.data;
  156. }
  157. console.log(key_name);
  158. linkage_vue.setData(select_id, key_name)
  159. }
  160. },
  161. error: function() {
  162. layer.msg('服务器繁忙,请稍后再试!!!', {
  163. icon: 3,
  164. time: 2000
  165. });
  166. }
  167. });
  168. }
  169. },
  170. watch: {
  171. '_props.options.tier_num':function(){
  172. console.log('获取到父级数据变化:' + this._props.options.tier_num);
  173. this.tier=this._props.options.tier_num;
  174. }
  175. },
  176. created() {
  177. this.getDataList('one_name',this._props.options.one_id);
  178. if (this._props.options.one_id > 0) {
  179. this.getDataList('two_name',this._props.options.two_id);
  180. }
  181. if (this._props.options.two_id > 0) {
  182. this.getDataList('three_name',this._props.options.three_id);
  183. }
  184. }
  185. }
  186. </script>
  187. <style scoped>
  188. .classJs {
  189. margin-left: 10px;
  190. vertical-align: middle;
  191. height: 42px;
  192. line-height: 42px;
  193. }
  194. .red {
  195. color: red;
  196. }
  197. </style>