Blame view

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

265 266 267 268 269 270 271 272 273 274 275 276
      // 删除
      /**
       * @description: 删除
       * @param {*} index
       * @param {*} row
       * @author: renchao
       */
      deleClick (index, row) {
        this.$confirm("确定要删除吗, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
xiaomiao committed
277
        })
278 279 280 281 282 283
          .then(() => {
            this.tableDataList.splice(index, 1);
            this.$emit("upDateTdytxxList", this.tableDataList);
          })
          .catch(() => { });
      },
xiaomiao committed
284
    },
285
  };
xiaomiao committed
286 287
</script>
<style scoped lang="scss">
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
  .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;
  }
  /deep/ .el-table--border .el-table__cell:first-child .cell {
    text-align: center;
  }
303 304 305
  /deep/.el-table--small .el-table__cell {
    padding: 3px 0 !important;
  }
xiaomiao committed
306
</style>