zuozhengqing
2024-03-20 f4ed5ae8873f65c36b5cf37be264f6ec1e154647
src/views/other/commonDialog/SelectCommonDialog.vue
@@ -28,37 +28,68 @@
            <el-button type="primary" size="mini" disabled>快速创建</el-button> -->
          </div>
        </div>
        <TableCommonView ref="tableListRef" :table-list="tableList" :select-box="false" @selCommonClick="selNameClick">
        <TableCommonView
          class="bg-list"
          ref="tableListRef"
          :table-list="tableList"
          :select-box="editCommonConfig.isSelectBox"
          :selectBoxList="selectBoxList"
          @selCommonClick="selNameClick"
          @selTableCol="selTableCol"
          @getSelectArray="getSelectArray"
        >
        </TableCommonView>
        <div slot="footer" class="dialog-footer">
          <div class="remark">说明:支持多字段模糊查询,仅显示符合条件的前5条数据</div>
          <!-- <div class="remark">说明:支持多字段模糊查询,仅显示符合条件的前5条数据</div> -->
          <div class="btn-pager">
            <PagerView class="page" :pager-options="pagerOptions" v-on="pagerEvents" />
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" v-if="editCommonConfig.isSelectBox">
        <el-button type="primary" size="small" @click="saveClick()">确定</el-button>
        <el-button size="small" @click="editConfig.editVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getProductList } from "@/api/common/other"
import { getProductListFromGrpc, getProductList } from "@/api/productManage/product"
import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
export default {
  name: "EditSelCommonDialog",
  mixins: [pageMixin],
  props: {
    editCommonConfig: {
      type: Object,
      default: () => {
        return {
          editVisible: false,
          isSelectBox: false,
          title: "",
          clientId: 0,
          isRequest: true,
          client_name: "",
          tableInfomation: []
        }
      }
    },
    sign: {
      type: String,
      default: ""
    },
    selectBoxList: {
      type: Array,
      default: () => []
    }
  },
  components: {},
  computed: {},
  data() {
    return {
      dialogWidth: "50%",
      dialogWidth: "40%",
      editConfig: this.editCommonConfig,
      queryInput: "",
      select: "全部字段",
@@ -70,7 +101,19 @@
      search_map: {},
      searchSel: {},
      keyword: "",
      keywordType: ""
      keywordType: "",
      showProductCol: ["产品名称", "产品编号", "销售单价", "单位", "产品规格", "型号"],
      tableProductColumn: [
        { label: "产品名称", prop: "name", isClick: true },
        { label: "产品编号", prop: "number" },
        { label: "销售单价", prop: "purchasePrice" },
        { label: "单位", prop: "unit" },
        { label: "产品规格", prop: "specifications" },
        { label: "型号", prop: "modelNumber" }
      ],
      showCol: [],
      tableColumn: [],
      selectArray: []
    }
  },
  created() {
@@ -78,23 +121,48 @@
    this.getData()
  },
  methods: {
    setColumnVisible(showCol) {
      return this.tableColumn.map((ele) => {
        return {
          ...ele,
          isShowColumn: showCol.includes(ele.label)
        }
      })
    },
    setTable() {
      if (this.editConfig.title === "产品名称") {
        this.tableList = {
          tableInfomation: [],
          tableColumn: [
            { label: "产品名称", prop: "name", isClick: true },
            { label: "产品编号", prop: "number" }
          ]
        }
        this.searchSel = { value: "name", label: "产品名称" }
        this.showCol = this.showProductCol
        this.tableColumn = this.tableProductColumn
      }
      this.tableList = {
        tableInfomation: [],
        selectIndex: true,
        highlight: true,
        ref: "tableListRef",
        showcol: this.showCol,
        allcol: [],
        tableColumn: this.setColumnVisible(this.showCol)
      }
      this.tableList.allcol = this.tableList.tableColumn.filter((ele) => !ele.default).map((ele) => ele.label)
      this.searchOptions = []
      for (let i = 0; i < this.tableList.tableColumn.length; i++) {
        const label = this.tableList.tableColumn[i].label
        const value = this.tableList.tableColumn[i].prop
        this.searchOptions.push({ value: value, label: label })
      }
    },
    selTableCol(val) {
      this.showcol = val
      this.tableList.tableColumn = this.setColumnVisible(val)
    },
    // 列表多选
    getSelectArray(val) {
      this.selectArray = val
    },
    saveClick() {
      this.$emit("getSelectArray", this.selectArray)
      this.editConfig.editVisible = false
    },
    // 请求数据
    async getData() {
@@ -105,21 +173,21 @@
    },
    // 产品名称
    async getProductList() {
      await getProductList({
        productName: this.keywordType === "产品名称" ? this.keyword : "",
        productNumber: this.keywordType === "产品编号" ? this.keyword : "",
        page: 1,
        pageSize: 5
      let fn = this.sign == "purchase" ? getProductList : getProductListFromGrpc
      await fn({
        keyword: this.keyword,
        page: this.pagerOptions.currPage,
        pageSize: this.pagerOptions.pageSize
      }).then((res) => {
        console.log(res.data)
        if (res.data.code === 200) {
          if (res.data.data.data && res.data.data.data.length > 0) {
            const list = res.data.data.data.map((item) => {
        if (res.code === 200) {
          if (res.data.list && res.data.list.length > 0) {
            const list = res.data.list.map((item) => {
              return {
                ...item
              }
            })
            this.tableList.tableInfomation = list.slice(0, 5) || []
            this.tableList.tableInfomation = list
            this.pagerOptions.totalCount = res.data.total
          } else {
            this.tableList.tableInfomation = []
          }
@@ -137,13 +205,9 @@
      }
    },
    // 搜索
    searchClick(val, content) {
      console.log(val, content)
      this.search_map = {
        [val.value]: content
      }
    searchClick(content) {
      console.log(content)
      this.keyword = content
      this.keywordType = val.label
      this.getData()
    },
    resetClick() {
@@ -181,9 +245,16 @@
  cursor: pointer;
}
.dialog-footer {
  height: 40px;
  line-height: 40px;
  height: 50px;
  line-height: 50px;
  color: red;
  .btn-pager {
    display: flex;
    margin-top: 0px;
    .page {
      margin-left: auto;
    }
  }
}
::v-deep {
  .input-with-select .el-input-group__prepend {