Blame view

src/views/workflow/components/tdytTable.vue 8.13 KB
xiaomiao committed
1 2 3
<!--
 * @Description:
 * @Autor: renchao
4
 * @LastEditTime: 2023-07-17 13:52:47
xiaomiao committed
5 6 7
-->
<template>
  <div>
xiaomiao committed
8 9 10
    <el-table
      :data="tableDataList"
      border
xiaomiao committed
11 12
      :pagination="false"
      :key="key"
xiaomiao committed
13
      :header-cell-style="{ 'text-align': 'center' }"
xiaomiao committed
14 15
      :heightNumSetting="true"
      :minHeight="150"
xiaomiao committed
16
      height="150"
xiaomiao committed
17 18
      style="width: 100%"
    >
xiaomiao committed
19
      <el-table-column prop="index" width="50" :render-header="renderHeader">
20
        <template slot-scope="scope">
xiaomiao committed
21 22
          <i
            class="el-icon-minus pointer"
xiaomiao committed
23
            @click="deleClick(scope.$index, scope.row)"
xiaomiao committed
24 25
            v-if="ableOperation"
          ></i>
xiaomiao committed
26 27
          <div style="text-align: center" v-else>
            {{ scope.$index + 1 }}
xiaomiao committed
28
          </div>
xiaomiao committed
29 30
        </template>
      </el-table-column>
xiaomiao committed
31
      <el-table-column prop="yt" label="土地用途" min-width="100">
xiaomiao committed
32
        <template slot-scope="scope">
33
          <treeselect
xiaomiao committed
34
            v-model="scope.row.yt"
xiaomiao committed
35
            :disabled="!ableOperation"
36
            noOptionsText="暂无数据"
xiaomiao committed
37
            placeholder=""
38 39 40
            :show-count="true"
            :options="dictData['tdyt']"
            :normalizer="normalizer"
xiaomiao committed
41 42
            :appendToBody="true"
            z-index="9999"
xiaomiao committed
43
            @input="addrow(scope.row)"
xiaomiao committed
44
          />
xiaomiao committed
45 46 47
        </template>
      </el-table-column>
      <el-table-column prop="qssj" label="土地使用起始时间" min-width="100">
48 49
        <template slot-scope="scope">
          <el-date-picker
xiaomiao committed
50
            v-model="scope.row.qssj"
51
            type="date"
52
            :disabled="!ableOperation"
xiaomiao committed
53
            :picker-options="scope.row.pickerStart"
54 55 56
            placeholder="选择日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd"
xiaomiao committed
57 58
            @input="startTime(scope.$index)"
          >
59
          </el-date-picker>
xiaomiao committed
60 61 62
        </template>
      </el-table-column>
      <el-table-column prop="jssj" label="土地使用结束时间" min-width="100">
63 64
        <template slot-scope="scope">
          <el-date-picker
xiaomiao committed
65
            v-model="scope.row.jssj"
66
            type="date"
67
            :disabled="!ableOperation"
xiaomiao committed
68
            :picker-options="scope.row.pickerEnd"
69 70 71
            placeholder="选择日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd"
xiaomiao committed
72 73
            @input="endTime(scope.$index)"
          >
74
          </el-date-picker>
xiaomiao committed
75 76
        </template>
      </el-table-column>
77
      <el-table-column prop="tdsyqx" label="土地使用期限" min-width="100">
78
        <template slot-scope="scope">
xiaomiao committed
79 80
          <el-input
            class="item"
81
            :disabled="!ableOperation"
xiaomiao committed
82 83
            v-model="scope.row.tdsyqx"
            oninput="value = (value.match(/^\d*(\.?\d{0,2})/g)[0]) || null"
xiaomiao committed
84
            placeholder="请输入内容"
xiaomiao committed
85 86 87 88
            @input="sumTime(scope.$index, scope.row.tdsyqx)"
          >
            ></el-input
          >
xiaomiao committed
89 90 91
        </template>
      </el-table-column>
    </el-table>
xiaomiao committed
92 93 94
  </div>
</template>
<script>
xiaomiao committed
95 96 97 98 99 100 101 102 103 104 105
import { mapGetters } from "vuex";
export default {
  computed: {
    ...mapGetters(["dictData"]),
  },
  props: {
    tableData: {
      type: Array,
      default: function () {
        return [];
      },
xiaomiao committed
106
    },
xiaomiao committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    ableOperation: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      // 键名转换,方法默认是label和children进行树状渲染
      key: 0,
      newdata: {
        yt: null,
        qssj: "",
        jssj: "",
        tdsyqx: "",
      },
      tableDataList: [],
      // 起始时间选择范围
      pickerStart: {},
      pickerEnd: {},
      normalizer(node) {
        if (node.children == null || node.children == "null") {
          delete node.children;
        }
        return {
          id: node.dcode,
          label: node.dname,
          children: node.children,
        };
xiaomiao committed
135
      },
xiaomiao committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    };
  },
  mounted() {},
  watch: {
    tableData: {
      handler: function (val, oldVal) {
        let that = this;
        this.$nextTick(() => {
          if (val.length == 0 || !val) {
            that.tableDataList = _.cloneDeep([
              {
                yt: null,
                qssj: "",
                jssj: "",
                tdsyqx: "",
              },
            ]);
          } else {
            that.tableDataList = _.cloneDeep(val);
          }
        });
xiaomiao committed
157
      },
xiaomiao committed
158 159
      immediate: true,
      deep: true,
160
    },
xiaomiao committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
  },
  methods: {
    /**
     * @description: renderHeader
     * @author: renchao
     */
    renderHeader() {
      return (
        <div>
          {" "}
          {!this.ableOperation ? (
            "序号"
          ) : (
            <i
              class="el-icon-plus pointer"
              onClick={() => {
                this.addClick();
              }}
            ></i>
          )}
        </div>
      );
    },
    // 修改事件
    /**
     * @description: 修改事件
     * @author: renchao
     */
    addrow(a) {
      console.log(a);
      // this.tableDataList = this.tableDataList.map((item) => {
      //   return {
      //     ...item,
xiaomiao committed
194
      //     yt: a.yt,
xiaomiao committed
195 196
      //   };
      // });
xiaomiao committed
197
      this.$emit("upDateTdytxxList", this.tableDataList);
xiaomiao committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    },
    /**
     * @description: startTime
     * @param {*} index
     * @author: renchao
     */
    startTime(index) {
      console.log("index", index);
      //  let startTime = this.tableDataList[index].tdsyqssj;
      let endTime = this.tableDataList[index].jssj;
      let startTime = this.tableDataList[index].qssj;
      this.tableDataList[index].pickerEnd = {
        disabledDate: (time) => {
          if (Object.keys(startTime).length > 0) {
            return new Date(startTime).getTime() > time.getTime();
          } else {
            return time.getTime() < Date.now();
xiaomiao committed
215
          }
216 217
        },
      };
xiaomiao committed
218 219 220 221 222 223
      if (startTime && endTime) {
        let startYear = new Date(startTime).getFullYear();
        let endYear = new Date(endTime).getFullYear();
        this.tableDataList[index].tdsyqx = endYear - startYear;
      }
      this.$emit("upDateTdytxxList", this.tableDataList);
xiaomiao committed
224
    },
xiaomiao committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
    /**
     * @description: endTime
     * @param {*} index
     * @author: renchao
     */
    endTime(index) {
      //  let startTime = this.tableDataList[index].tdsyqssj;
      let startTime = this.tableDataList[index].qssj;
      let endTime = this.tableDataList[index].jssj;
      this.tableDataList[index].pickerStart = {
        disabledDate: (time) => {
          if (Object.keys(endTime).length > 0) {
            return new Date(endTime).getTime() < time.getTime();
          } else {
            return time.getTime() > Date.now();
          }
241
        },
xiaomiao committed
242 243 244 245 246 247 248
      };
      if (startTime && endTime) {
        let startYear = new Date(startTime).getFullYear();
        let endYear = new Date(endTime).getFullYear();
        this.tableDataList[index].tdsyqx = endYear - startYear;
      }
      this.$emit("upDateTdytxxList", this.tableDataList);
xiaomiao committed
249
    },
xiaomiao committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
    /**
     * @description: sumTime
     * @param {*} index
     * @param {*} tdsyqx
     * @author: renchao
     */
    sumTime(index, tdsyqx) {
      let startTime = this.tableDataList[index].qssj;
      this.tableDataList[index].jssj =
        Number(startTime.substring(0, 4)) +
        Number(tdsyqx) +
        startTime.slice(4, 19);
      this.$emit("upDateTdytxxList", this.tableDataList);
    },
    // 新增
    /**
     * @description: 新增
     * @author: renchao
     */
    addClick() {
      this.tableDataList[this.tableDataList.length] = _.cloneDeep(this.newdata);
xiaomiao committed
271

xiaomiao committed
272 273
      this.$emit("upDateTdytxxList", this.tableDataList);
    },
xiaomiao committed
274

xiaomiao committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
    // 删除
    /**
     * @description: 删除
     * @param {*} index
     * @param {*} row
     * @author: renchao
     */
    deleClick(index, row) {
      this.$confirm("确定要删除吗, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.tableData.splice(index, 1);
xiaomiao committed
290
        })
xiaomiao committed
291 292
        .catch(() => {});
      this.$emit("upDateTdytxxList", this.tableDataList);
xiaomiao committed
293
    },
xiaomiao committed
294 295
  },
};
xiaomiao committed
296 297
</script>
<style scoped lang="scss">
xiaomiao committed
298 299 300 301 302 303 304 305 306 307 308 309
.el-input {
  border: none !important;
}
/deep/.el-table__row {
  border: none !important;
}
.el-date-editor.el-input {
  width: 100%;
}
/deep/.el-table th {
  height: 30px !important;
}
xiaomiao committed
310
</style>