addMapping.vue 13.2 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 406 407 408
<!--
 * @Author: yangming yangming@didihu.com.cn
 * @Date: 2023-01-04 14:00:10
 * @LastEditors: yangming yangming@didihu.com.cn
 * @LastEditTime: 2023-01-11 13:57:22
 * @FilePath: \scrm-micro-mapping\src\views\mapping\addMapping.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="mapping-main">
    <div class="mapping-container" v-loading="loading">
      <div class="box-title">{{ editStatus ? '编辑' : '新增' }}标签映射</div>
      <div class="box-form gl-form-page">
        <el-form ref="ruleForm" :model="addForm" :rules="rules" label-width="154px">
          <div class="el-form-item el-form-item--small is-required">
            <label class="el-form-item__label" style="width: 154px;">选择门店:</label>
            <div class="el-form-item__content" style="margin-left: 154px;">
              <!-- <el-select v-model="merchantId" placeholder="请选择" filterable @change="queryGroupListByMerchantId" size="small" :disabled="editStatus">
                <el-option v-for="item in selectMerchant" :key="item.merchantNo" :label="item.merchantName" :value="item.merchantNo"></el-option>
              </el-select> -->
              <el-button type="default" class="el-icon-plus" v-if="!editStatus" @click="handleRelateStoreClose">选择商户</el-button>
              <div class="merchantNameLabel" v-if="merchantName">
                <p>已选门店:{{ merchantName }},商户号:{{ merchantId }}</p>
              </div>
            </div>
          </div>
          <el-form-item label="所属工厂:" size="small" v-if="topMerchantName">
            <el-input v-model="topMerchantName" :disabled="true"></el-input>
          </el-form-item>
          <div class="el-form-item el-form-item--small is-required">
            <label class="el-form-item__label" style="width: 154px;">标签:</label>
            <div class="el-form-item__content" style="margin-left: 154px;">
              <div class="tag-panel">
                <div class="tag-item" v-for="(item, index) in groupList" :key="item">
                  <div class="tag-item-select">
                    <el-select v-model="item.groupValue_l" placeholder="请选择" filterable @change="changeGroup_l(item)" size="small">
                      <el-option v-for="item in groupList_l" :key="item" :label="item" :value="item"></el-option>
                    </el-select>
                    <el-select v-model="item.sysLabelName" placeholder="请选择" filterable @change="changeTag_l(item)" size="small">
                      <el-option v-for="i in item.tagList_l" :key="i.labelName" :label="i.labelName" :value="i.labelName"></el-option>
                    </el-select>
                  </div>
                  <div class="tag-img"><img src="@/assets/mapping.png" alt="" /></div>
                  <div class="tag-item-select">
                    <el-select v-model="item.groupValue_r" placeholder="请选择" filterable @change="changeGroup_r(item)" size="small">
                      <el-option v-for="item in groupList_r" :key="item" :label="item" :value="item"></el-option>
                    </el-select>
                    <el-select v-model="item.envLabelName" placeholder="请选择" filterable @change="changeTag_r(item)" size="small">
                      <el-option v-for="i in item.tagList_r" :key="i.labelName" :label="i.labelName" :value="i.labelName"></el-option>
                    </el-select>
                  </div>
                  <div class="tag-icon" @click="delTag(index)" v-if="index > 0">
                    <i class="el-icon-delete"></i>
                  </div>
                </div>
                <div class="tag-add" @click="addTag">
                  <i class="el-icon-circle-plus-outline"></i>
                  新增标签
                </div>
              </div>
            </div>
          </div>
        </el-form>
      </div>
    </div>
    <GLFooter>
      <el-button @click="handleCancel" size="medium">取消</el-button>
      <el-button type="primary" @click="handleConfirm" size="medium" :loading="loading">提交</el-button>
    </GLFooter>
    <select-store v-if="relateStoreVisible" ref="relateStore" :dialogVisible="relateStoreVisible" :storeSelected="selectedList" :merchantInfo="merchantId" @handleRelateStoreConfirm="handleRelateStoreConfirm" @handleRelateStoreClose="handleRelateStoreClose"></select-store>
  </div>
</template>

<script>
const tagType = [
  {
    name: '系统标签',
    type: 1
  },
  {
    name: '企业标签',
    type: 2
  }
]
const tagJson = {
  groupValue_l: '',
  groupValue_r: '',
  tagList_l: [],
  tagList_r: [],
  envLabelId: '',
  sysLabelId: '',
  sysGroupId: '',
  envGroupId: '',
  sysLabelName: '',
  envLabelName: ''
}
import selectStore from './components/selectStore'
export default {
  name: 'addMapping',
  components: {
    selectStore
  },
  data() {
    return {
      relateStoreVisible: false,
      editStatus: false,
      loading: false,
      addForm: {},
      topMerchantName: '',
      selectMerchant: [],
      groupList: [{ ...tagJson }],
      groupList_l: [],
      groupList_r: [],
      merchantId: '',
      merchantName: '',
      tagList: []
    }
  },
  watch: {
    merchantId() {
      this.queryGroupListByMerchantId()
      this.findTopMerchantInfo()
    }
  },
  methods: {
    // 选择门店
    handleRelateStoreClose() {
      // console.log('handleRelateStoreClose')
      // this.selectedList = this.$common.utils.deepClone(this.editForm.supplyMerchantList)
      this.relateStoreVisible = !this.relateStoreVisible
    },
    handleRelateStoreConfirm(selectedData) {
      console.log(selectedData)
      // this.$refs.editFormRef.$refs[this.editChildRef].clearValidate('merchantId')
      // this.editForm.supplyMerchantList = selectedData
      this.merchantId = selectedData.merchantId
      this.merchantName = selectedData.merchantName
      // this.selectedList = selectedData
      this.handleRelateStoreClose()
    },
    addTag() {
      this.groupList.push({ ...tagJson })
    },
    delTag(index) {
      this.groupList.splice(index, 1)
    },
    handleCancel() {
      this.$router.push('/mapping/index')
    },
    handleConfirm() {
      if (!this.merchantId) {
        this.$message.error('请选择门店')
        return
      }
      const labelRelation = this.groupList.map(item => {
        return {
          envLabelId: item.envLabelId,
          sysLabelId: item.sysLabelId,
          sysGroupId: item.sysGroupId,
          envGroupId: item.envGroupId
        }
      })
      for (let label of labelRelation) {
        if (!label.envLabelId || !label.sysLabelId || !label.sysGroupId || !label.envGroupId) {
          this.$message.error('请选择标签')
          return
        }
      }
      const params = {
        req: {
          merchantId: this.merchantId,
          labelRelation: JSON.stringify(labelRelation)
        }
      }
      let relation = 'addLabelRelation'
      if (this.editStatus) {
        relation = 'editLabelRelation'
      }
      this.$apis.mapping[relation](params).then(res => {
        if (res.code == 0) {
          this.$message.success('操作成功')
          this.handleCancel()
        }
      })
      //   this.$refs.ruleFormy.validate(valid => {
      //     if (valid) {
      //       console.log(this.groupList)
      //       const params = {
      //         req: {
      //           merchantId: this.merchantId,
      //           labelRelation: [
      //             { envGroupId: 389, envLabelId: 1611, sysGroupId: 383, sysLabelId: 1622 },
      //             { envGroupId: 389, envLabelId: 1612, sysGroupId: 383, sysLabelId: 1623 }
      //           ]
      //         }
      //       }
      //       this.$apis.mapping.addLabelRelation(params).then(res => {
      //         this.groupList_r = res.groupList
      //       })
      //     }
      //   })
    },
    //改变系统标签
    changeGroup_l(group, status) {
      this.queryLabelListByGroupName(group, 1, status)
    },
    //改变系统标签
    changeGroup_r(group, status) {
      this.queryLabelListByGroupName(group, 2, status)
    },
    //改变系统标签
    changeTag_l(group) {
      this.queryLabelListByTagName(group, 1)
    },
    //改变系统标签
    changeTag_r(group) {
      this.queryLabelListByTagName(group, 2)
    },
    queryLabelListByTagName(group, type) {
      if (type == 1) {
        group.sysLabelId = group.tagList_l.find(tag => tag.labelName == group.sysLabelName)?.labelId
      }
      if (type == 2) {
        group.envLabelId = group.tagList_r.find(tag => tag.labelName == group.envLabelName)?.labelId
      }
    },
    queryGroupListByMerchantId() {
      this.groupList = [{ ...tagJson }]
      const params = {
        req: {
          merchantId: this.merchantId,
          groupType: '系统标签'
        }
      }
      this.$apis.mapping.queryGroupListByMerchantId(params).then(res => {
        this.groupList_l = res.groupList
      })
      const params2 = {
        req: {
          merchantId: this.merchantId,
          groupType: '企业标签'
        }
      }
      this.$apis.mapping.queryGroupListByMerchantId(params2).then(res => {
        this.groupList_r = res.groupList
        console.log(this.groupList_r)
      })
    },
    queryLabelListByGroupName(item, type, status) {
      let groupType = tagType.find(i => i.type == type).name,
        groupName
      if (type == 1) {
        groupName = item.groupValue_l
        if (!status) {
          item.sysLabelName = ''
          item.tagList_l = []
          item.sysGroupId = ''
        }
      } else {
        groupName = item.groupValue_r
        if (!status) {
          item.tagList_r = []
          item.envLabelName = ''
          item.envGroupId = ''
        }
      }

      const params = {
        req: {
          merchantId: this.merchantId,
          groupType,
          groupName
        }
      }
      this.$apis.mapping.queryLabelListByGroupName(params).then(res => {
        if (type == 1) {
          item.tagList_l = res.labelUnitList
          item.sysGroupId = res.groupId
        } else {
          item.tagList_r = res.labelUnitList
          item.envGroupId = res.groupId
        }
      })
    },
    findTopMerchantInfo() {
      this.$apis.mapping.findTopMerchantInfo({ merchantNoStr: this.merchantId }).then(res => {
        this.topMerchantName = res && res[0]?.topMerchantName
      })
    },
    async findMerchantListByPage() {
      const { merchantId, merchantName } = this.$route.query
      if (merchantId) {
        this.editStatus = true
        this.merchantId = +merchantId
        this.merchantName = merchantName
        this.queryGroupListByMerchantId()
        this.$apis.mapping.queryLabelRelation({ req: { merchantId } }).then(res => {
          if (res.relationUnitList && res.relationUnitList.length) {
            this.groupList = res.relationUnitList.map(item => {
              return {
                groupValue_l: item.sysGroupName,
                groupValue_r: item.envGroupName,
                envLabelName: item.envLabelName,
                sysLabelName: item.sysLabelName,
                tagList_l: [],
                tagList_r: [],
                envLabelId: item.envLabelId,
                sysLabelId: item.sysLabelId,
                sysGroupId: item.sysGroupId,
                envGroupId: item.envGroupId
              }
            })
            this.groupList.forEach(item => {
              this.changeGroup_l(item, 1)
              this.changeGroup_r(item, 1)
            })
          } else {
            this.groupList = [{ ...tagJson }]
          }
        })
      }
    }
  },

  mounted() {
    // this.queryGroupListByMerchantId()
    this.findMerchantListByPage()
  }
}
</script>
<style lang="scss" scoped>
.mapping-container {
  background: #ffffff;
  min-height: calc(100vh - 136px);
  margin-bottom: 16px;
  .merchantNameLabel {
    width: 510px;
    color: #1d1d1d;
    // margin-left: 50px;
    padding: 16px;
    margin-top: 8px;
    border: 1px solid #e6e6e6;
    border-radius: 8rpx;
    background: #f9f9f9;
    .merchantName {
      box-sizing: border-box;
      width: 284px;
      height: 32px;
      background: #ffffff;
      border: 1px solid #e6e6e6;
      border-radius: 4px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 14px;
      color: #999999;
      line-height: 32px;
      padding: 0 8px;
    }
  }
  .box-title {
    height: 56px;
    line-height: 56px;
    padding-left: 20px;
    border-bottom: 1px solid #e5e5e5;
    font-weight: 600;
    font-size: 16px;
    color: #333333;
  }
  .box-form {
    padding: 20px;
    .tag-panel {
      .tag-add {
        color: #5850ff;
        cursor: pointer;
        i {
          font-size: 18px;
          vertical-align: middle;
        }
      }
      .tag-item {
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        .tag-icon {
          color: #999;
          cursor: pointer;
        }
        .tag-img {
          img {
            width: 16px;
            height: 16px;
            margin-right: 10px;
          }
        }
        .tag-item-select {
          display: flex;
          /deep/ {
            .el-select,
            .el-input {
              width: 166px;
            }
          }
        }
      }
    }
  }
}
</style>