Newer
Older
smartKitchenFront / src / components / mycomponent / dialog / productBindDialog.vue
<!--产品列表绑定服务弹窗-->
<template>
  <el-dialog title="绑定服务" width="900px" :visible.sync="isShowInfo" append-to-body @close="close">
    <div class="product-inputBox">
      <div class="input-item">
        产品型号:
        <el-input v-model="dataInfo.productCode" disabled style="width:200px" />
      </div>
      <div class="input-item">
        产品名称:
        <el-input v-model="dataInfo.productName" disabled style="width:200px" />
      </div>
    </div>
    <div class="product-bindTable">
      <div class="bindBtn">
        <el-button type="primary" @click="bindServeClick">
          添加服务
        </el-button>
      </div>
      <el-table ref="tb" v-loading="loading" :data="tableData" border class="el-tab" style="width: 100%;">
        <el-table-column type="index" label="#" width="60px" />
        <el-table-column prop="serviceCode" label="服务编号">
          <template slot-scope="{row,$index}">
            <el-select v-model="row.id" clearable placeholder="请选择" @change="val=>changeService(val,$index)">
              <el-option
                v-for="item in serviceList"
                :key="item.id"
                :label="item.serviceCode"
                :value="item.id"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="typeCodeName" label="服务类型" />
        <el-table-column prop="description" label="服务描述" />
        <el-table-column prop="serviceTime" label="服务时间" />
        <el-table-column prop="remark" label="备注" />
      </el-table>
    </div>
    <div class="btnBox">
      <el-button type="primary" class="save" @click="bindService">
        保存
      </el-button>
      <el-button type="info" class="close" @click="close">
        取消
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { M_list } from '@/api/server/Management'
import { bindServ, listBindService } from '@/api/product/product'
export default {
  props: {
    dataInfo: {
      type: Object,
      dataInfo: {}
    }
  },
  data() {
    return {
      loading: true,
      tableData: [],
      isShowInfo: false,
      serviceList: [],
      serviceId: ''
    }
  },
  mounted() {
    M_list().then(res => {
      this.serviceList = res
    })
  },
  methods: {
    close() {
      this.isShowInfo = false
      this.$emit('close')
    },
    initDialog(row) {
      this.isShowInfo = true
      if (this.dataInfo) {
        this.fetchBindList(row.id)
      }
    },
    fetchBindList(id) {
      this.loading = true
      listBindService({ id: id }).then(res => {
        this.tableData = res
        this.loading = false
      })
    },
    bindServeClick() {
      const obj = {
        id: '',
        serviceCode: '',
        serviceName: '',
        typeCode: '',
        typeCodeName: '',
        description: '',
        serviceTime: '',
        remark: ''
      }
      this.tableData.push(obj)
    },
    changeService(val, index) {
      const service = this.serviceList.filter(item => item.id == val)[0]
      this.tableData[index].id = service.id
      this.tableData[index].serviceCode = service.serviceCode
      this.tableData[index].serviceName = service.serviceName
      this.tableData[index].typeCode = service.typeCode
      this.tableData[index].typeCodeName = service.typeCodeName
      this.tableData[index].description = service.description
      this.tableData[index].serviceTime = service.serviceTime
      this.tableData[index].remark = service.remark
    },
    bindService() {
      const serviceIds = this.tableData.map(item => item.id)
      const data = {
        serviceIds: serviceIds,
        productId: this.dataInfo.id
      }
      bindServ(data).then(res => {
        this.$message.success('绑定成功')
        this.close()
      })
    }
  }
}
</script>

<style lang='scss' scoped>
.product-inputBox {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
}

.product-bindTable {
  display: flex;
  flex-direction: column;
  align-items: flex-end;

  .bindBtn {
    margin-bottom: 10px;
  }
}

.btnBox {
  padding: 30px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-evenly;

  .save,
  .close {
    width: 100px;
  }

}
</style>