suxinf 5 gadi atpakaļ
vecāks
revīzija
a657aae840

+ 170 - 3
src/views/parameter/LinkUpload.vue

@@ -1,20 +1,187 @@
 <template>
-  <div class="car_series">
-      链接上传
+  <div>
+  <div class="link_upload">
+    <div class="count">
+      <div class="select">
+        <p>上传平台</p>
+        <select @change="slectPlatForm()" v-model="selectedForm">
+          <option 
+            v-for="(item, index) in optionList" :key="index"
+            :value="item"
+          >
+            {{item}}
+          </option>
+        </select>
+      </div>
+      <div @click="showModal" class="current_button">新增</div>
+    </div>
+    <div class="table">
+      <Table
+        :tableData='tableData'
+        @edit='edit'
+        @delet_data='deleteData'
+        :pageSize='sum'
+      ></Table>
+    </div>
+    <div class="page">
+      <Tablepage
+        :totalPage='totalPage'
+        :currentPage='currentPage'
+        @change_page='changePage'
+        @jump_page='jumpPage'
+      ></Tablepage>
+      <Count :sum='sum'></Count>
+    </div>
+    <div class="modal" v-if="modalFlag">
+      <Modal
+        :modalFlag='modalFlag'
+        :selectedForm='selectedForm'
+        @submit='submit'
+        @hide_modal='showModal'
+      ></Modal>
+    </div>
+  </div>
   </div>
 </template>
 
 <script>
+import Count from '../../components/Count';
+import Tablepage from '../../components/TablePage';
+import Table from './components/LinkUpload/Table';
+import Modal from "./components/LinkUpload/Modal";
+
 export default {
+  components: {
+    Count,
+    Table,
+    Tablepage,
+    Modal
+  },
   data() {
     return {
+      sum: 86, // 一共有多少条数据
+      pageSize: 20, // 每页展示的数据
+      currentPage: 1,
+      tableData: [],
+      getDate: [
+        {time: '2021/03', plate: '汽车之家', num: 5, str: '222'},
+        {time: '2021/03', plate: '汽车之家', num: 5, str: '111'},
+        {time: '2021/03', plate: '汽车之家', num: 5, str: '333'}
+      ],
+      functionData: [],
+      modalFlag: false, // 控制模态框展示
+      optionList: ['汽车之家', 'aa', 'bb', 'ss'],
+      selectedForm: '汽车之家'
+    }
+  },
+  computed:{
+    // 表格总页数
+    totalPage() {
+      return Math.ceil(this.sum/this.pageSize);
+    },
+    // 获取路由参数
+    queryTag() {
+      console.log (111, this.$route.query);
+      return (this.$route.query && this.$route.query.tag) ? 0 : 1
+    }
+  },
+  methods: {
+    // 获取某一页面的数据,展示在表格
+    changePage: function(page) {
+      this.currentPage = page;
+      console.log(page);
+    },
+    // 点击上一页,下一页,首页,尾页
+    jumpPage: function(item) {
+      switch(item) {
+        case 1:
+          this.currentPage = 1;
+          break;
+        case 2:
+          this.currentPage = this.currentPage - 1;
+          break;
+        case 3:
+          this.currentPage = this.currentPage + 1;
+          break;
+        case 4:
+          this.currentPage = this.totalPage;
+          break;
+      }
+      console.log(this.currentPage);
+    },
+    // 获取数据
+    getData: function() {
+      this.tableData = [];
+      this.functionData = [];
+      this.getDate.forEach( (element) => {
+        this.tableData.push(
+          {
+            time: element.time,
+            plate: element.plate,
+            num: element.num
+          }
+        );
+        this.functionData.push(
+          {
+            str: element.str
+          }
+        )
+      });
+    },
+    // 展示、隐藏模态框
+    showModal: function() {
+      this.modalFlag = !this.modalFlag;
+    },
+    // 点击编辑
+    edit (index, newName) {
+      console.log(this.functionData[index].str, newName);
+    },
+    // 点击删除
+    deleteData (index) {
+      console.log('删除', this.functionData[index].str)
+    },
+    // 模态框保存
+    submit: function(time, num) {
+        console.log('保存', time, num);
+        this.modalFlag = false;
+    },
+    // slectPlatForm
+    slectPlatForm: function() {
+      console.log(this.selectedForm);
     }
   },
   mounted() {
+    this.getData();
   }
 }
 </script>
 
 <style scoped lang="less">
-
+.link_upload{
+  .count{
+      margin-top: 10px;
+    width: 100%;
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+    .select{
+      display: flex;
+      padding-left: 20px;
+      p{
+        height: 28px;
+        line-height: 28px;
+        width: 70px;
+      }
+      select{
+        border: 1px solid #ccc;
+        height: 28px;
+        width: 144px;
+        color: #555;
+      }
+    }
+  }
+  .page{
+    display: flex;
+  }
+}
 </style>

+ 133 - 0
src/views/parameter/components/LinkUpload/Modal.vue

@@ -0,0 +1,133 @@
+<template>
+  <div v-if="modalFlag">
+    <div class="vehicle_servies_modal">
+      <div class="modal_content">
+        <div class="time">
+          <p>选择时间</p>
+          <input type="month" v-model="time" />
+        </div>
+        <div class="plate">
+          <p>选择平台</p>
+          <p>{{ selectedForm }}</p>
+        </div>
+        <div class="num">
+          <p>设置上传数量</p>
+          <input type="text" v-model="num" />
+        </div>
+        <div class="btn">
+          <button @click="submit" style="margin: 0">保存</button>
+          <button @click="hideModal" style="margin: 0">取消</button>
+        </div>
+      </div>
+    </div>
+  </div>
+</template>
+
+<script>
+export default {
+  props: {
+    modalFlag: {
+      type: Boolean,
+      default: false,
+    },
+    selectedForm: {
+      type: String,
+      default: "",
+    },
+  },
+  data() {
+    return {
+      time: "",
+      num: 0,
+    };
+  },
+  methods: {
+    submit: function () {
+        if(!this.num) {
+            alert('请选择上传数量');
+            return
+        }
+        let num = +this.num;
+        if(typeof(num) !== 'number') {
+            alert('请输入大于零的数字');
+        } else  if(num <=0 ) {
+            alert('请输入大于零的整数');
+        } else if ( Math.ceil(num) !== num) {
+            alert('请输入大于零的整数');
+        } else {
+            this.$emit("submit", this.time, this.num);
+        }
+    },
+    hideModal: function () {
+      this.$emit("hide_modal");
+    },
+  },
+};
+</script>
+
+<style scoped lang="less">
+.vehicle_servies_modal {
+  position: fixed;
+  left: 0;
+  top: 0;
+  height: 100vh;
+  width: 100vw;
+  background-color: rgba(127, 127, 127, 0.7);
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  .modal_content {
+    width: 600px;
+    height: 400px;
+    background-color: #fff;
+    transform: translateY(-80px);
+    padding-left: 240px;
+    .time {
+      margin-top: 80px;
+      display: flex;
+      height: 28px;
+      p {
+        width: 80px;
+        height: 28px;
+        line-height: 28px;
+        margin-right: 20px;
+      }
+      input {
+        height: 28px;
+        width: 200px;
+        border: 1px solid #ccc;
+        color: #555;
+      }
+    }
+    .plate {
+      margin-top: 20px;
+      margin-right: 20px;
+      display: flex;
+      p {
+        width: 100px;
+      }
+    }
+    .num {
+      display: flex;
+      margin-top: 20px;
+      p {
+        height: 28px;
+        line-height: 28px;
+        width: 100px;
+      }
+      input {
+        color: #555;
+        height: 28px;
+        width: 200px;
+        border: 1px solid #ccc;
+      }
+    }
+    .btn {
+      width: 200px;
+      margin-top: 30px;
+      display: flex;
+      justify-content: space-between;
+    }
+  }
+}
+</style>

+ 157 - 0
src/views/parameter/components/LinkUpload/Table.vue

@@ -0,0 +1,157 @@
+<template>
+  <div class="table">
+    <table>
+      <thead>
+        <tr>
+          <td>时间</td>
+          <td>上传平台</td>
+          <td>链接上传数量</td>
+          <td>操作</td>
+        </tr>
+      </thead>
+      <tbody>
+        <tr
+          v-for="(obj, index) in tableData"
+          :key="index"
+          :class="{ table_gray: index % 2 === 0 }"
+        >
+          <td>{{obj.time}}</td>
+          <td>{{obj.plate}}</td>
+          <td style="width: 20%">
+            <p v-if="!editFlag[index]">{{ obj.num }}</p>
+            <input
+              type="text"
+              v-model="newName"
+              v-else
+              :placeholder="obj.num"
+            />
+          </td>
+          <td style="width: 25%" class="operation">
+            <span @click="edit(index)" v-if="!editFlag[index]">编辑</span>
+            <span @click="submitEdit(index)" v-else>确定</span>
+            <span @click="showModal(index)">删除</span>
+          </td>
+        </tr>
+      </tbody>
+    </table>
+    <DeleteModal
+      @detlet_data="detletData"
+      @hide_modal="closeModal"
+      :modalFlag="deleteModalFlag"
+    ></DeleteModal>
+  </div>
+</template>
+
+<script>
+import DeleteModal from "../DeleteModal";
+export default {
+  props: {
+    // 表数据
+    tableData: {
+      type: Array,
+      default: () => {
+        return [];
+      },
+    },
+    //  表格一页共有多少数据
+    pageSize: {
+      type: Number,
+      default: 2,
+    },
+  },
+  components: {
+    DeleteModal,
+  },
+  data() {
+    return {
+      deleteModalFlag: false,
+      index: 0,
+      editFlag: [],
+      newName: "", // 编辑之后的值
+    };
+  },
+  methods: {
+    edit: function (i) {
+      this.getEditArr(); // 确保只有一个在编辑
+      this.newName = this.tableData[i] && this.tableData[i].num;
+      console.log(this.newName);
+      this.editFlag.splice(i, 1, true);
+    },
+    // 确认编辑
+    submitEdit: function (i) {
+
+      if (!this.newName || typeof(this.newName) !== 'number') {
+        alert("空值或者不是数字");
+      } else if (this.newName === this.tableData[i].num) {
+        this.newName = ""; // 没有改
+      } else {
+        this.$emit("edit", i, this.newName);
+      }
+      this.newName = "";
+      this.editFlag.splice(i, 1, false);
+    },
+    // 点击删除,展示模态框
+    showModal: function (i) {
+      this.deleteModalFlag = true;
+      this.index = i;
+    },
+    // 模态框确认删除
+    detletData: function () {
+      this.deleteModalFlag = false;
+      this.$emit("delet_data", this.index);
+    },
+    // 模态框取消
+    closeModal: function () {
+      this.deleteModalFlag = false;
+    },
+    // 生成点击编辑按钮所用额flag,
+    getEditArr: function () {
+      let arr = new Array(this.pageSize).fill(false);
+      this.editFlag = arr;
+    },
+    mounted() {
+      this.getEditArr();
+    },
+  },
+};
+</script>
+
+<style scoped lang="less">
+.table {
+  background-color: #fff;
+  width: 100%;
+  margin-top: 10px;
+  text-align: center;
+  table {
+    width: 100%;
+    border-collapse: collapse;
+    border: none;
+    thead {
+      td {
+        background: #8d9092;
+        height: 36px;
+        color: #fff;
+        border: 1px solid #ccc;
+      }
+    }
+    tbody {
+      td {
+        height: 36px;
+        border: 1px solid #ccc;
+      }
+      .operation {
+        span {
+          color: #00f;
+          margin: 0 20px;
+          &:hover {
+            cursor: pointer;
+          }
+        }
+      }
+    }
+  }
+}
+.table_gray {
+    background: #f5f5f5
+}
+</style>