serviceManage.vue 13.3 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 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
<!-- 服务商管理 -->
<template>
  <d2-container class="service-manage">
    <div class="header"
         slot="header">
      <d2-search ref="showSearch"
                 class="show-search"
                 :search-form="searchForm"
                 :form-data="showFormData" />
      <div class="up-btns">
        <el-button :id="tableParams.btnId"
                   size="small"
                   type="primary">
          查询
        </el-button>
        <el-button size="small"
                   @click="handleReset">
          重置
        </el-button>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table-header>
        <span slot="left">园区店服务商关联列表</span>
        <!-- <auth-button category="Button" /> -->
      </d2-table-header>
      <d2-table ref="serviceStoreTable"
                :search-form="searchForm"
                :table-params="tableParams"
                :get-list-api="getListApi"
                :before-search-fn="beforeSearchFn">
                <!-- <auth-button slot="auth-button"
                     slot-scope="scope"
                     :data="scope.scope" /> -->
      </d2-table>
    </div>
    <!-- 新增服务商 -->
    <d2-dialog title="关联服务商"
               :is-visible.sync="relateVisible"
               btn-ok-label="确定关联"
               width="60%"
               class="relate-dialog"
               @confirmDialog="handleRelateConfirm"
               @closeDialog="handleRelateClose">
      <span slot="sub-title">为园区店关联对应的服务商,一家园区店只能关联一个服务商</span>
      <el-form ref="relateDialog"
               :model="relateForm"
               :rules="relateRule"
               label-width="150px">
        <el-form-item label="选择关联的园区店:"
                      prop="yqMerchantId">
          <el-select v-model="relateForm.yqMerchantId"
                     filterable>
            <el-option v-for="item in baseData.yqList.filter(i => i.merchantName !== '全部')"
                       :key="item.merchantId"
                       :value="item.merchantId"
                       :label="item.merchantName"
                       :disabled="item.disabled" />
          </el-select>
          <span class="relate-dialog-tips">您选择的园区店编号:{{ relateForm.yqMerchantId }}</span>
        </el-form-item>
        <el-form-item label="选择关联的服务商:"
                      prop="merchantId">
          <el-select v-model="relateForm.merchantId"
                     multiple
                     :multiple-limit="5"
                     filterable
                     style="width:400px">
            <el-option v-for="item in baseData.serviceList.filter(i => i.merchantName !== '全部')"
                       :key="item.merchantId"
                       :value="item.merchantId"
                       :label="item.merchantName" />
          </el-select>
          <span class="relate-dialog-tips">您选择的服务商编号:{{ relateForm.merchantId }}</span>
        </el-form-item>
      </el-form>
    </d2-dialog>
    <!-- 删除服务商 -->
    <d2-dialog title="删除服务商"
               :is-visible.sync="deleteVisible"
               width="750px"
               class="delete-dialog"
               @confirmDialog="handleDeleteConfirm"
               @closeDialog="handleDeleteClose">
      <p class="delete-title">
        删除园区店和服务商的关联记录,会同步暂停该园区店跟该服务商的分润,是否继续删除?
      </p>
      <el-form ref="deleteDialog"
               :model="deleteForm"
               :rules="deleteRule"
               label-width="150px">
        <el-form-item label="管理员手机验证:">
          {{ adminInfo.name }} {{ adminInfo.phone }}
          <el-button size="small"
                     @click="handleSend"
                     :disabled="isSend">
            {{ isSend ? sendMsg + '秒后,重试' : '发送验证短信' }}
          </el-button>
        </el-form-item>
        <el-form-item label="验证码:"
                      prop="smsCode">
          <el-input placeholder="请填写验证码"
                    v-model="deleteForm.smsCode" />
        </el-form-item>
      </el-form>
    </d2-dialog>
  </d2-container>
</template>

<script>
import { Util, deepClone } from '@/common/util'
// addParentMerchant,
import { getList, getMerchantList, deleteParentMerchant, saveParentMerchant } from '@api/serviceManage'
import { getParkStore } from '@api/editCustomer'
import { mapActions } from 'vuex'
import { BaseData } from '@/common/constants.js'
import { sendSms, getAdminInfo } from '@api/merchant'
export default {
  name: 'ServiceManage',
  data() {
    return {
      searchForm: {
        merchantNameKeyWord: '',
        merchantIdKeyWord: ''
      },
      showFormData: [{
        label: '商户名称',
        name: 'merchantNameKeyWord',
        type: 'input',
        placeholder: '请输入服务商/园区店名称',
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '商户号',
        name: 'merchantIdKeyWord',
        type: 'input',
        inputType: 'number',
        maxlength: '9',
        placeholder: '请输入服务商/园区店编号',
        isClear: true,
        keyFn: this.keyDowmGetList
      }],
      maxLength: 10,
      getListApi: getList,
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        // tableOption: true,
        tableColumns: [{
          label: '园区店名称',
          prop: 'yqMerchantName'
        }, {
          label: '园区店号',
          prop: 'yqMerchantId',
          width: '120'
        }, {
          label: '登录账户',
          prop: 'accountName',
          width: '200',
          html: true,
          formatter: (cellValue) => {
            var html = ''
            var list = []
            if (cellValue.partnerMerchantList && cellValue.partnerMerchantList.length > 0) {
              cellValue.partnerMerchantList.map(item => {
                list.push(item.accountName)
              })
              html = list.join('<br>')
            }
            return html
          }
        }, {
          label: '关联服务商名称',
          prop: 'merchantName',
          width: '200',
          html: true,
          formatter: (cellValue) => {
            var html = ''
            var list = []
            if (cellValue.partnerMerchantList && cellValue.partnerMerchantList.length > 0) {
              cellValue.partnerMerchantList.map(item => {
                list.push(item.merchantName)
              })
              html = list.join('<br>')
            }
            return html
          }
        }, {
          label: '关联服务商号',
          prop: 'merchantId',
          width: '200',
          html: true,
          formatter: (cellValue) => {
            var html = ''
            var list = []
            if (cellValue.partnerMerchantList && cellValue.partnerMerchantList.length > 0) {
              cellValue.partnerMerchantList.map(item => {
                list.push(item.merchantId)
              })
              html = list.join('<br>')
            }
            return html
          }
        }, {
          label: '最近更新时间',
          prop: 'lastRefDate',
          width: '160',
          formatter: (cellValue) => {
            return Util.dateFormate(cellValue.lastRefDate, 'YYYY-MM-DD HH:mm:ss')
          }
        }]
      },
      // 关联服务商
      relateVisible: false,
      relateForm: {},
      relateRule: {
        yqMerchantId: [{ required: true, message: '请选择园区店', trigger: 'change' }],
        merchantId: [{ required: true, message: '请选择服务商', trigger: 'change' }]
      },
      // 删除服务商
      deleteVisible: false,
      deleteForm: {},
      deleteRule: {
        smsCode: [{ required: true, message: '请输入验证码', trigger: 'change' }]
      },
      isSend: false,
      sendMsg: '发送验证短信',
      time: '',
      adminInfo: {
        name: '',
        phone: ''
      },
      baseData: {
        yqList: [],
        serviceList: [],
        channelType: []
      }
    }
  },

  components: {
  },

  mounted() {
    this.getBaseData()
    getAdminInfo({}).then(res => {
      this.adminInfo = res
    })
  },

  methods: {
    ...mapActions('d2admin/base', ['get']),
    beforeSearchFn() {
      return new Promise(resolve => {
        resolve()
      })
    },

    async getBaseData() {
      this.baseData.channelType = await this.get(BaseData.channelType)
    },
    keyDowmGetList() {
      this.$refs.serviceStoreTable.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        merchantNameKeyWord: '',
        merchantIdKeyWord: ''
      }
    },
    // 新增服务商
    handleRelate() {
      this.handleRelateClose()
    },
    handleRelateClose() {
      this.relateVisible = !this.relateVisible
      this.relateForm = { merchantId: [] }
      this.$refs.relateDialog && this.$refs.relateDialog.resetFields()
      if (this.relateVisible) {
        // 园区店
        // getMerchantList({
        //   // merchantType: 6,
        //   merchantTypeList: [6, 8],
        //   channelType: 1,
        //   filterWithPartner: true
        // }).then(res => {
        //   res.forEach(item => {
        //     item.merchantId = item.merchantNo
        //   })
        //   this.baseData.yqList = res
        // })
        getParkStore({}).then(res => {
          res.forEach(item => {
            item.merchantId = item.merchantNo
          })
          this.baseData.yqList = res
        })
        // 服务商
        getMerchantList({
          merchantType: 7,
          channelType: 1
        }).then(res => {
          res.forEach(item => {
            item.merchantId = item.merchantNo
          })
          this.baseData.serviceList = res
        })
      }
    },
    handleRelateConfirm() {
      this.$refs.relateDialog.validate(valid => {
        if (valid) {
          // var serviceItem = this.baseData.serviceList.find(item => item.merchantId === this.relateForm.merchantId)
          const serviceItemList = []
          this.baseData.serviceList.map(item => {
            // item.merchantId === this.relateForm.merchantId
            this.relateForm.merchantId.map((ele) => {
              if (ele == item.merchantId) {
                serviceItemList.push(item)
              }
            })
          })
          console.log(serviceItemList)

          var params = {
            ...this.relateForm,
            yqMerchantName: this.baseData.yqList.find(item => item.merchantId === this.relateForm.yqMerchantId).merchantName,
            // ...serviceItem
            list: serviceItemList
          }
          console.log(params)
          // addParentMerchant({ data: params }).then(res => {
          //   this.notice.okTips()
          //   this.handleRelateClose()
          //   this.keyDowmGetList()
          // })

          saveParentMerchant(params).then(res => {
            this.notice.okTips()
            this.handleRelateClose()
            this.keyDowmGetList()
          })
        }
      })
    },
    // 删除服务商
    handleDelete(row) {
      this.recordId = row.id
      var record = deepClone(row)
      this.handleDeleteClose(record)
    },
    handleDeleteClose(record) {
      this.deleteVisible = !this.deleteVisible
      if (record) {
        this.deleteForm = { yqMerchantId: record.yqMerchantId }
      } else {
        this.deleteForm = {}
      }
      this.isSend = false
      this.time && clearTimeout(this.time)
      this.$refs.deleteDialog && this.$refs.deleteDialog.resetFields()
    },
    handleDeleteConfirm() {
      this.$refs.deleteDialog.validate(valid => {
        if (valid) {
          deleteParentMerchant({ id: this.recordId, smsCode: this.deleteForm.smsCode, yqMerchantId: this.deleteForm.yqMerchantId }).then(res => {
            // console.log(res)
            this.notice.okTips('删除成功')
            this.handleDeleteClose()
            this.keyDowmGetList()
          })
        }
      })
    },
    handleSend() {
      sendSms({}).then((res) => {
        this.notice.okTips('已发送,30分钟内有效')
        this.isSend = true
        this.sendMsg = 60
        this.msgDown()
      })
    },
    msgDown() {
      this.time = setTimeout(() => {
        clearTimeout(this.time)
        if (this.sendMsg > 1) {
          --this.sendMsg
          this.msgDown()
        } else {
          this.isSend = false
        }
      }, 1000)
    }
  }
}

</script>
<style scoped>
.relate-dialog-tips {
  display: inline-block;
  margin-left: 20px;
}
.delete-dialog .delete-title {
  font-size: 16px;
}
::v-deep .service-manage {
  /*下拉选择框-多选-内容过长-用...代替    begin    */
  .el-tag.el-tag--info {
    background-color: #f4f4f5;
    border-color: #e9e9eb;
    color: #909399;
    max-width: calc(100% - 50px);
    /* white-space: nowrap;
     text-overflow: ellipsis;
     overflow: hidden;*/
  }
  .el-tag.el-tag--info {
    width: calc(100% - 200px);
  }
  .el-tag.el-tag--info .el-select__tags-text {
    width: calc(100% - 20px);
    float: left;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  /*下拉选择框-多选-内容过长-用...代替    end    */

  .el-select-dropdown__item {
    width: 395px !important;
  }
}
</style>