<p>以下是整理后的代码:</p>
<template>
  <div style="padding: 5px 20px;">
    <br>
    <el-form :inline="true" :model="listQuery" class="demo-form-inline">
      <el-form-item label="代收单位名">
        <el-input v-model="listQuery.unit_name" placeholder="代收单位名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmitSelect" icon="el-icon-search">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="TJCollectionForm" icon="el-icon-edit">添加</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格-->
    <el-table :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="ID" width="50" type="index">
      </el-table-column>
      <el-table-column label="代收单位账号" prop="unit_account">
      </el-table-column>
      <el-table-column label="代收单位名称" prop="unit_name">
      </el-table-column>
      <el-table-column label="创建时间">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>&nbsp;
          <span style="margin-left: 5px" v-text="(scope.row.create_time).substring(-1,19).replace('T',' ')"></span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="修改密码" placement="top">
            <el-button type="primary" icon="el-icon-edit" circle @click="BJCollectionForm(scope.$index)"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="删除" placement="top">
            <el-button type="danger" icon="el-icon-delete" circle @click="deleteVisible(scope)"></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
<pre><code>&lt;el-pagination @size-change=&quot;handleSizeChange&quot; @current-change=&quot;handleCurrentChange&quot; :current-page=&quot;listQuery.page&quot;
  :page-sizes=&quot;[10]&quot; :page-size=&quot;listQuery.limit&quot; layout=&quot;total, sizes, prev, pager, next, jumper&quot; :total=&quot;total&quot;
  :background=&quot;true&quot;&gt;
&lt;/el-pagination&gt;

&lt;el-dialog :title=&quot;textMap[dialogStatus]&quot; :visible.sync=&quot;dialogFormVisible&quot;&gt;
  &lt;el-form ref=&quot;collectionform&quot; :rules=&quot;rules&quot; :model=&quot;ruleForm&quot; label-width=&quot;120px&quot; label-position=&quot;left&quot;&gt;
    &lt;el-form-item label=&quot;代收单位账号&quot; prop=&quot;unit_account&quot; v-if=&quot;dialogStatus=='create'&quot;&gt;
      &lt;el-input placeholder=&quot;代收单位账号&quot; v-model=&quot;ruleForm.unit_account&quot;&gt;&lt;/el-input&gt;
    &lt;/el-form-item&gt;
    &lt;el-form-item label=&quot;代收单位名称&quot; prop=&quot;unit_name&quot; v-if=&quot;dialogStatus=='create'&quot;&gt;
      &lt;el-input placeholder=&quot;代收单位名称&quot; v-model=&quot;ruleForm.unit_name&quot;&gt;&lt;/el-input&gt;
    &lt;/el-form-item&gt;
    &lt;el-form-item label=&quot;代收单位密码&quot; prop=&quot;unit_password&quot;&gt;
      &lt;el-input placeholder=&quot;代收单位密码&quot; v-model=&quot;ruleForm.unit_password&quot;&gt;&lt;/el-input&gt;
    &lt;/el-form-item&gt;
  &lt;/el-form&gt;
  &lt;div slot=&quot;footer&quot; class=&quot;dialog-footer&quot;&gt;
    &lt;el-button @click=&quot;dialogFormVisible = false&quot;&gt;取 消&lt;/el-button&gt;
    &lt;el-button type=&quot;primary&quot; v-if=&quot;dialogStatus=='create'&quot; @click=&quot;submitCollectionForm('collectionform')&quot;&gt;添 加&lt;/el-button&gt;
    &lt;el-button type=&quot;warning&quot; v-else @click=&quot;updateCollectionForm('collectionform')&quot;&gt;修 改&lt;/el-button&gt;
  &lt;/div&gt;
&lt;/el-dialog&gt;
</code></pre>
  </div>
</template>
<script>
export default {
  name: 'department',
  data() {
    return {
      listLoading: true,
      list: null,
      total: 0,
      listQuery: {
        page: 1,
        limit: 10,
        unit_name: ''
      },
      dialogFormVisible: false,
      dialogStatus: 'create',
      textMap: {
        update: '修改代收单位',
        create: '添加代收单位'
      },
      ruleForm: {
        id: '',
        unit_code: '',
        unit_account: '',
        unit_name: '',
        unit_password: '',
        create_time: '',
        create_author: '',
      },
      rules: {
        unit_account: [{
          required: true,
          message: '请输入代收单位账号',
          trigger: 'blur'
        }],
        unit_name: [{
          required: true,
          message: '请输入代收单位名称',
          trigger: 'blur'
        }],
        unit_password: [{
          required: true,
          message: '请输入代收单位密码',
          trigger: 'blur'
        }]
      }
    }
  },
  created() {
    this.axiosdata()
  },
  methods: {
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.axiosdata();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.axiosdata();
    },
    onSubmitSelect() {
      this.axiosdata()
    },
    axiosdata() {
      this.listLoading = true;
      this.$axios({
        method: 'post',
        url: '/page/getHs_collection_unit',
        headers: {
          'token': this.$store.getters.token
        },
        data: this.listQuery
      }).then((response) => {
        this.listLoading = false;
        this.list = response.data.result.list;
        this.total = response.data.result.total;
      })
    },
    TJCollectionForm() {
      Object.assign(this.$data.ruleForm, this.$options.data().ruleForm);
      this.dialogStatus = "create";
      this.dialogFormVisible = true;
    },
    BJCollectionForm($index) {
      this.ruleForm = JSON.parse(JSON.stringify(this.list[$index]));
      this.dialogStatus = "update";
      this.dialogFormVisible = true;
    },
    submitCollectionForm(formname) {
      this.$refs[formname].validate((valid) => {
        if (valid) {
          this.$axios({
            method: 'post',
            url: '/inserths_collection_unit',
            data: this.ruleForm
          }).then((response) => {
            if (response.data.resStatus.resCode == 0) {
              this.axiosdata();
              this.dialogFormVisible = false;
              this.$message.success('添加数据成功!');
            } else {
              this.$message.error('添加数据失败!');
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    updateCollectionForm(formname) {
      this.$refs[formname].validate((valid) => {
        if (valid) {
          this.$axios({
            method: 'post',
            url: '/updatehs_collection_unit',
            data: this.ruleForm
          }).then((response) => {
            if (response.data.resStatus.resCode == 0) {
              this.axiosdata();
              this.dialogFormVisible = false;
              this.$message.success('修改数据成功!');
            } else {
              this.$message.error('修改数据失败!');
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    deleteVisible(scope) {
      this.$confirm('确定要删除【' + scope.row.unit_name + '】吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios({
          method: 'post',
          url: '/deletehs_collection_unit',
          data: scope.row
        }).then((response) => {
          if (response.data.resStatus.resCode == 0) {
            this.axiosdata();
            this.dialogFormVisible = false;
            this.$message.error('删除完毕');
          } else {
            this.$message.error('删除数据失败!');
          }
        })
      });
    },
  },
}
</script>
<style>
</style
帮我整理一下代码template div style=padding 5px 20px; br el-form inline=true model=listQuery class=demo-form-inline el-form-item label=代收单位名 el-input v-model=listQueryunit_name placeholder=代

原文地址: https://www.cveoy.top/t/topic/hON4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录