| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <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.publishMonth || "" }}</td>
- <td>{{ obj.publishPlatformName || selectedplateForm.platformName }}</td>
- <td style="width: 20%">
- <p v-if="!editFlag[index]">{{ obj.publishCount || "" }}</p>
- <input type="text" v-model="newName" v-else />
- </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,
- },
- selectedplateForm: {
- type: Object,
- default: () => {
- return {}
- }
- }
- },
- components: {
- DeleteModal,
- },
- data() {
- return {
- deleteModalFlag: false,
- index: 0,
- editFlag: [],
- newName: "", // 编辑之后的值
- };
- },
- methods: {
- edit: function (i) {
- this.getEditArr(); // 确保只有一个在编辑
- this.newName = this.tableData[i] && this.tableData[i].publishCount;
- console.log(this.newName);
- this.editFlag.splice(i, 1, true);
- },
- // 确认编辑
- submitEdit: function (i) {
- let newCount = +this.newName;
- if (!newCount) {
- alert("请填写链接上传数量");
- } else if (newCount === this.tableData[i].publishCount) {
- this.newName = ""; // 没有改
- } else if (Math.ceil(newCount) !== newCount || Math.ceil(newCount) <=0) {
- alert("链接上传数量必须是大于零的整数");
- } else {
- this.$emit("edit", i, newCount);
- }
- 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;
- },
- },
- created() {
- 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>
|