goodsFreight.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="province">
  3. <el-checkbox
  4. :indeterminate="isIndeterminate"
  5. v-model="province.checked"
  6. :disabled="province.disabled"
  7. @change="changeProvince"
  8. >{{ province.name }}
  9. </el-checkbox>
  10. <svg class="changeIcon" aria-hidden="true" @click.stop="openSingle">
  11. <use :xlink:href="iconChange"></use>
  12. </svg>
  13. <transition name="fade">
  14. <div
  15. class="singleArea"
  16. v-show="itemShow && province.cityList.length"
  17. >
  18. <svg
  19. class="changeIcon"
  20. aria-hidden="true"
  21. @click.stop="closeSingle"
  22. >
  23. <use xlink:href="#icon-close"></use>
  24. </svg>
  25. <el-checkbox-group v-model="province.city" @change="handleCheckedCitiesChange">
  26. <el-checkbox
  27. v-for="(item, index) in province.cityList"
  28. :key="index"
  29. :label="item.code"
  30. :disabled="item.disabled"
  31. >{{ item.name }}
  32. </el-checkbox>
  33. </el-checkbox-group>
  34. </div>
  35. </transition>
  36. </div>
  37. </template>
  38. <script>
  39. export default {
  40. name: 'goods-freight',
  41. props: {
  42. province: {
  43. type: Object
  44. },
  45. show: {
  46. type: Boolean
  47. },
  48. index: {
  49. type: Number
  50. }
  51. },
  52. data() {
  53. return {
  54. isIndeterminate: false,
  55. itemShow: false,
  56. iconChange: '#icon-arrowdropdown'
  57. };
  58. },
  59. created() {
  60. },
  61. methods: {
  62. openSingle() {
  63. this.iconChange = this.itemShow
  64. ? '#icon-arrowdropdown'
  65. : '#icon-arrowdropup';
  66. this.$emit('changeShow', this.index, !this.itemShow);
  67. },
  68. changeProvince(val) {
  69. // 根据省份的选择状态更改市级状态
  70. this.province.city = val ? this.province.cityList.map(item => item.code) : [];
  71. this.isIndeterminate = false;
  72. this.$emit('changeCity', this.index, this.province);
  73. },
  74. handleCheckedCitiesChange(value) {
  75. let checkedCount = value.length;
  76. this.province.checked = checkedCount === this.province.cityList.length;
  77. this.$emit('changeCity', this.index, this.province);
  78. this.isIndeterminate =
  79. checkedCount > 0 && checkedCount < this.province.cityList.length;
  80. },
  81. closeSingle() {
  82. this.iconChange = '#icon-arrowdropdown';
  83. this.$emit('changeShow', this.index, false);
  84. }
  85. },
  86. watch: {
  87. show(val) {
  88. this.itemShow = val;
  89. }
  90. }
  91. };
  92. </script>
  93. <style scoped lang="stylus" rel="stylesheet/stylus">
  94. @import '~assets/main.styl';
  95. .province {
  96. position: relative;
  97. width: 106px;
  98. margin-bottom: 10px;
  99. line-height: 30px;
  100. }
  101. .fade-enter-active, .fade-leave-active {
  102. transition: opacity 0.3s;
  103. }
  104. .fade-enter, .fade-leave-to { /* .fade-leave-active below version 2.1.8 */
  105. opacity: 0;
  106. }
  107. .el-checkbox {
  108. }
  109. .el-checkbox-group {
  110. flex-x();
  111. flex-wrap: wrap;
  112. }
  113. .changeIcon {
  114. width: 12px;
  115. height: 12px;
  116. fill: #666;
  117. position: absolute;
  118. right: 10px;
  119. top: 10px;
  120. cursor: pointer;
  121. }
  122. .singleArea {
  123. background: #efefef;
  124. padding: 20px 10px;
  125. width: 250px;
  126. position: absolute;
  127. left: 0;
  128. top: 30px;
  129. z-index: 99;
  130. }
  131. </style>