custom-dialog.vue 10.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
<template>
  <el-dialog
    class="entryDialog classCUploadDialog"
    title="自定义内容"
    :visible.sync="customVisible"
    v-loading="dialogLoading"
    :show-close="false"
    width="700px"
    :close-on-click-modal="false"
  >
    <div
      style="
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 30px;
      "
    >
      <div class="radio-group">
        <el-radio-group v-model="radio" @change="radioChange">
          <el-radio :label="3">物流运单编号维度</el-radio>
          <el-radio :label="6">商品维度</el-radio>
        </el-radio-group>
      </div>
      <template v-if="radio === 3">
        <el-transfer
          v-model="transferValue"
          :data="logisticsWaybillDimension"
          :right-default-checked="currentItem"
          filterable
          target-order="push"
          :props="{ label: 'itemChineseName', key: 'itemValue' }"
          :titles="['未选内容', '已选内容']"
          @right-check-change="choose"
        >
          <span
            class="el-icon-arrow-up"
            slot="right-footer"
            style="margin-left: 10px; cursor: pointer"
            @click="handleUp('transferValue')"
            title="上移"
          >
          </span>
          <span
            class="el-icon-arrow-down"
            slot="right-footer"
            style="cursor: pointer; margin-left: 8px"
            @click="handleDown('transferValue')"
            title="下移"
          >
          </span>
          <!-- <el-button
            class="transer-footer"
            size="mini"
        
            >上移</el-button
          > -->
          <!-- <el-button
            class="transer-footer"
            slot="right-footer"
            size="mini"
            @click="handleDown('transferValue')"
            >下移</el-button
          > -->
        </el-transfer>
      </template>
      <template v-if="radio === 6">
        <el-transfer
          v-model="transferValue1"
          :data="commodityDetailDimension"
          :right-default-checked="currentItem"
          filterable
          target-order="push"
          :props="{ label: 'itemChineseName', key: 'itemValue' }"
          :titles="['未选内容', '已选内容']"
          @right-check-change="choose"
        >
          <span
            class="el-icon-arrow-up"
            slot="right-footer"
            style="margin-left: 10px; cursor: pointer"
            @click="handleUp('transferValue1')"
            title="上移"
          >
          </span>
          <span
            class="el-icon-arrow-down"
            slot="right-footer"
            style="cursor: pointer; margin-left: 8px"
            @click="handleDown('transferValue1')"
            title="下移"
          >
          </span>
          <!-- <el-button
            class="transer-footer"
            slot="right-footer"
            style="margin-left: 10px"
            size="mini"
            @click="handleUp('transferValue1')"
            >上移</el-button
          >
          <el-button
            class="transer-footer"
            slot="right-footer"
            size="mini"
            @click="handleDown('transferValue1')"
            >下移</el-button
          > -->
        </el-transfer>
      </template>
    </div>
    <div class="dialogOption entrySave revokeOperation">
      <el-button
        class="entrySaveButton entrySaveButton-background revokeSubmitBtn"
        type="primary"
        @click="formSubmit"
      >
        确定
      </el-button>
      <el-button class="entrySaveButton" @click="cancelModify">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getDictData } from "@/api/system/dict-api.js";
import {
  getCustomizeExcelFormat,
  getCustomizeExcel,
} from "@/api/exportList-api.js";

export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false,
    },
    selectedDatas: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    const generateData = (_) => {
      const data = [];
      for (let i = 1; i <= 15; i++) {
        data.push({
          key: i,
          label: `备选项 ${i}`,
          disabled: i % 4 === 0,
        });
      }
      return data;
    };
    return {
      customVisible: false,
      dialogLoading: false,
      transferValue: [],
      transferValue1: [],
      data: generateData(),
      radio: 3,
      commodityDetailDimension: [],
      logisticsWaybillDimension: [],
      historyInfo: {},
      currentItem: [],
    };
  },
  watch: {
    showDialog(val) {
      if (val) {
        this.customVisible = val;
        this.getList();
        this.radio = 3;
      }
    },
  },
  created() {},
  methods: {
    async getList() {
      // COMMODITY_DETAIL_DIMENSION 商品明细维度字典code
      // LOGISTICS_WAYBILL_DIMENSION 物流运单编号维度字典code
      await getDictData({
        doctCode: "COMMODITY_DETAIL_DIMENSION",
      }).then((res) => {
        if (res.code === "200") {
          this.commodityDetailDimension = res.data;
        }
      });
      await getDictData({
        doctCode: "LOGISTICS_WAYBILL_DIMENSION",
      }).then((res) => {
        if (res.code === "200") {
          this.logisticsWaybillDimension = res.data;
        }
      });
      await getCustomizeExcel({}).then((res) => {
        if (res.code === "200") {
          this.transferValue = res.data.logisticsWaybillDimension
            ? res.data.logisticsWaybillDimension
            : res.data.defaultLogisticsWaybill;
          this.transferValue1 = res.data.commodityDetailDimension
            ? res.data.commodityDetailDimension
            : res.data.defaultCommodityDetail;
          this.historyInfo = res.data;
          this.$nextTick(() => {
            this.commodityDetailDimension = this.commodityDetailDimension.map(
              (item) => {
                return {
                  ...item,
                  disabled: res.data.defaultCommodityDetail.includes(
                    item.itemValue
                  ),
                };
              }
            );
            this.logisticsWaybillDimension = this.logisticsWaybillDimension.map(
              (item) => {
                return {
                  ...item,
                  disabled: res.data.defaultLogisticsWaybill.includes(
                    item.itemValue
                  ),
                };
              }
            );
          });
        }
      });
    },
    radioChange(e) {
      console.log(e);
      if (e === 3) {
        this.transferValue = this.historyInfo.logisticsWaybillDimension
          ? this.historyInfo.logisticsWaybillDimension
          : this.historyInfo.defaultLogisticsWaybill;
      } else if (e === 6) {
        this.transferValue1 = this.historyInfo.commodityDetailDimension
          ? this.historyInfo.commodityDetailDimension
          : this.historyInfo.defaultCommodityDetail;
      }
      this.currentItem = [];
    },

    formSubmit() {
      let params = {
        // 商品明细维度字段
        commodityDetailDimension: {},
        // 物流运单编号维度
        logisticsWaybillDimension: {},
      };

      // 物流运单编号维度 3
      params.logisticsWaybillDimension = this.transferValue.reduce(
        (acc, item) => {
          const dimension = this.logisticsWaybillDimension?.find(
            (dim) => dim?.itemValue === item
          );
          if (dimension?.itemChineseName) {
            acc[dimension.itemChineseName] = item;
          }
          return acc;
        },
        {}
      );
      params.commodityDetailDimension = this.transferValue1.reduce(
        (acc, item) => {
          const dimension = this.commodityDetailDimension?.find(
            (dim) => dim?.itemValue === item
          );
          if (dimension?.itemChineseName) {
            acc[dimension.itemChineseName] = item;
          }
          return acc;
        },
        {}
      );

      console.log("datas==", params);
      getCustomizeExcelFormat(params)
        .then((res) => {
          if (res.code === "200") {
            this.msgSuccess("修改成功");
            this.cancelModify(1);
          } else {
            this.alertWarningMsg(res.message);
            this.cancelModify(0);
          }
        })
        .catch((err) => {
          console.log(err);
          this.alertWarningMsg(err.message);
          this.cancelModify(0);
        });
    },

    cancelModify(val) {
      this.customVisible = false;
      this.dialogLoading = false;
      this.currentItem = [];
      this.$emit("cancelModify", val);
    },
    //===============
    //上移事件
    handleUp(key) {
      let self = this;
      let item = self.currentItem;
      let index;
      if (item.length == 1) {
        self[key].find((val, indexs, arr) => {
          if (val == item[0]) {
            index = indexs;
          }
        });
        if (index == 0) {
          self.msgError("已经到顶了");
          return;
        }
        //改变的数组
        let changeItem = JSON.parse(JSON.stringify(self[key][index - 1]));
        self[key].splice(index - 1, 1);
        self[key].splice(index, 0, changeItem);
      } else {
        self.msgError("只能选择一条数据进行上下移动");
        return;
      }
    },
    choose(value) {
      this.currentItem = value;
    }, //下移事件
    handleDown(key) {
      let self = this;
      let item = self.currentItem;
      let index;
      if (item.length == 1) {
        //选中值的下标
        self[key].find((val, indexs, arr) => {
          if (val == item) {
            index = indexs;
          }
        });
        if (index == self[key].length - 1) {
          // 这里是length-1,因为下标值从0开始
          self.msgError("已经到底了");
          return;
        }
        let changeItem = JSON.parse(JSON.stringify(self[key][index]));
        self[key].splice(index, 1);
        self[key].splice(index + 1, 0, changeItem);
      } else {
        self.msgError("只能选择一条数据进行上下移动");
        return;
      }
    },
    // ===========
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/styles/variables.scss";
::v-deep {
  .el-transfer-panel .el-checkbox__inner {
    height: 17px;
    width: 14px;
  }
  .el-button--primary,
  .el-button--primary:hover,
  .el-button--primary:focus {
    color: #ff6200;
  }
  /* .el-transfer-panel__list.is-filterable {
    padding-bottom: 40px;
  } */
  .el-transfer-panel__body {
    height: 260px;
  }
  .el-transfer-panel__list.is-filterable {
    height: 240px;
  }
  .is-with-footer {
    .el-transfer-panel__list.is-filterable {
      height: 205px;
    }
  }
  .el-transfer__buttons {
    display: inline-flex;
    flex-direction: column;
    .el-button + .el-button {
      margin-left: 0;
    }
  }
  .el-transfer-panel {
    width: 235px;
    height: 350px;
  }
}

.revokeOperation {
  margin-bottom: 25px;
  .revokeSubmitBtn {
    margin-right: 30px;
  }
}
</style>