Blame view

src/views/workflow/components/tdytTable.vue 8.62 KB
xiaomiao committed
1 2 3
<!--
 * @Description:
 * @Autor: renchao
4
 * @LastEditTime: 2023-09-12 09:40:17
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"
17
      style="width: 100%">
xiaomiao committed
18
      <el-table-column prop="index" width="50" :render-header="renderHeader">
19
        <template slot-scope="scope">
xiaomiao committed
20 21
          <i
            class="el-icon-minus pointer"
xiaomiao committed
22
            @click="deleClick(scope.$index, scope.row)"
23
            v-if="ableOperation"></i>
xiaomiao committed
24 25
          <div style="text-align: center" v-else>
            {{ scope.$index + 1 }}
xiaomiao committed
26
          </div>
xiaomiao committed
27 28
        </template>
      </el-table-column>
xiaomiao committed
29
      <el-table-column prop="yt" label="土地用途" min-width="100">
xiaomiao committed
30
        <template slot-scope="scope">
31
          <treeselect
xiaomiao committed
32
            v-model="scope.row.yt"
xiaomiao committed
33
            :disabled="!ableOperation"
34
            noOptionsText="暂无数据"
xiaomiao committed
35
            placeholder=""
36 37 38
            :show-count="true"
            :options="dictData['tdyt']"
            :normalizer="normalizer"
xiaomiao committed
39 40
            :appendToBody="true"
            z-index="9999"
41
            @input="addrow(scope.row)" />
xiaomiao committed
42 43 44
        </template>
      </el-table-column>
      <el-table-column prop="qssj" label="土地使用起始时间" min-width="100">
45 46
        <template slot-scope="scope">
          <el-date-picker
xiaomiao committed
47
            v-model="scope.row.qssj"
48
            type="date"
49
            :disabled="!ableOperation"
xiaomiao committed
50
            :picker-options="scope.row.pickerStart"
51 52 53
            placeholder="选择日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd"
54
            @input="startTime(scope.$index)">
55
          </el-date-picker>
xiaomiao committed
56 57 58
        </template>
      </el-table-column>
      <el-table-column prop="jssj" label="土地使用结束时间" min-width="100">
59 60
        <template slot-scope="scope">
          <el-date-picker
xiaomiao committed
61
            v-model="scope.row.jssj"
62
            type="date"
63
            :disabled="!ableOperation"
xiaomiao committed
64
            :picker-options="scope.row.pickerEnd"
65 66 67
            placeholder="选择日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd"
68
            @input="endTime(scope.$index)">
69
          </el-date-picker>
xiaomiao committed
70 71
        </template>
      </el-table-column>
72
      <el-table-column prop="tdsyqx" label="土地使用期限" min-width="100">
73
        <template slot-scope="scope">
xiaomiao committed
74 75
          <el-input
            class="item"
76
            :disabled="!ableOperation"
xiaomiao committed
77 78
            v-model="scope.row.tdsyqx"
            oninput="value = (value.match(/^\d*(\.?\d{0,2})/g)[0]) || null"
xiaomiao committed
79
            placeholder="请输入内容"
80 81
            @input="sumTime(scope.$index, scope.row.tdsyqx)">
            ></el-input>
xiaomiao committed
82 83 84
        </template>
      </el-table-column>
    </el-table>
xiaomiao committed
85 86 87
  </div>
</template>
<script>
88 89 90 91
  import { mapGetters } from "vuex";
  export default {
    computed: {
      ...mapGetters(["dictData"]),
xiaomiao committed
92
    },
93 94 95 96 97 98
    props: {
      tableData: {
        type: Array,
        default: function () {
          return [];
        },
xiaomiao committed
99
      },
100 101 102
      ableOperation: {
        type: Boolean,
        default: true,
xiaomiao committed
103
      },
104
    },
105 106 107 108 109 110 111 112 113
    data () {
      return {
        // 键名转换,方法默认是label和children进行树状渲染
        key: 0,
        newdata: {
          yt: null,
          qssj: "",
          jssj: "",
          tdsyqx: "",
114
        },
115 116 117 118 119 120 121
        tableDataList: [],
        // 起始时间选择范围
        pickerStart: {},
        pickerEnd: {},
        normalizer (node) {
          if (node.children == null || node.children == "null") {
            delete node.children;
xiaomiao committed
122
          }
123 124 125 126 127
          return {
            id: node.dcode,
            label: node.dname,
            children: node.children,
          };
128
        },
xiaomiao committed
129 130
      };
    },
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    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
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 264 265
    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
266

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