123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- <template>
- <zz-form :cols="formCols" :data="formData" :rules="formRules" labelWidth="120" ref="form">
- <template slot="communityId">
- <el-select class="width65" v-model="formData.communityId" clearable @change="handleChange">
- <el-option
- :label="item.communityName"
- :value="item.id"
- v-for="item in $store.getters['getAreaSelect']"
- :key="item.id"
- ></el-option>
- </el-select>
- </template>
- <template slot="cameraSettings">
- <el-select class="width65" v-model="formData.cameraSettings" clearable>
- <el-option label="是" :value="1"></el-option>
- <el-option label="否" :value="0"></el-option>
- </el-select>
- </template>
- <template slot="typeValue">
- <el-cascader
- :key="typeValueKey"
- ref="typeValue"
- v-model="typeValueW"
- :props="defaultProps"
- :options="deviceArr"
- @change="deviceArrToggle"
- ></el-cascader>
- <!-- <div style="text-align: center; margin-top: 20px">
- <el-transfer
- style="text-align: left; display: inline-block"
- v-model="formData.deviceIds"
- filterable
- :props="{
- key: 'id',
- label: 'deviceName'
- }"
- :titles="['待选列表', '已选列表']"
- :data="devicesArr"
- ></el-transfer>
- </div> -->
- </template>
- <template slot="deviceIds">
- <div style="text-align: center">
- <el-transfer
- style="text-align: left; display: inline-block"
- v-model="formData.deviceIds"
- filterable
- :props="{
- key: 'id',
- label: 'deviceName'
- }"
- :titles="['待选列表', '已选列表']"
- :data="devicesArr"
- ></el-transfer>
- </div>
- </template>
- <el-date-picker
- class="width100"
- slot="startDate"
- v-model="effectiveDate"
- value-format="yyyy-MM-dd "
- type="daterange"
- range-separator="至"
- start-placeholder="选择开始日期"
- end-placeholder="选择结束日期"
- @change="effectiveDateToggle"
- :editable="false"
- ></el-date-picker>
- <el-cascader
- ref="userName"
- v-model="formData.peopleId"
- :props="defaultProps1"
- slot="peopleId"
- :options="findUser"
- @change="findUserToggle"
- ></el-cascader>
- </zz-form>
- </template>
- <script >
- export default {
- props: ['params'],
- data() {
- return {
- formData: {
- communityId: '',
- inspectionName: '',
- cameraSettings: '',
- peopleId: '',
- peopleName: '',
- startDate: '',
- endDate: '',
- deviceIds: [],
- type: '',
- typeValue: '',
- remark: ''
- },
- formRules: {
- communityId: [this.$valid.selectRequired('社区')],
- peopleId: [this.$valid.selectRequired('巡检人员')],
- startDate: [this.$valid.selectRequired('巡检时间')],
- inspectionName: [this.$valid.inputRequired('巡检计划名称')],
- address: this.$valid.custome({
- validator(rule, value, cb) {
- const rl = rule;
- let regExp = /^.{1,20}$/;
- if (!value) {
- rl.message = '请输入地址';
- cb(new Error());
- } else if (!regExp.test(value)) {
- rl.message = '不能超过20个字';
- cb(new Error());
- } else {
- cb();
- }
- }
- }),
- repairName: this.$valid.custome({
- validator(rule, value, cb) {
- const rl = rule;
- let regExp = /^.{1,20}$/;
- if (!value) {
- rl.message = '请输入报修人';
- cb(new Error());
- } else if (!regExp.test(value)) {
- rl.message = '不能超过20个字';
- cb(new Error());
- } else {
- cb();
- }
- }
- }),
- typeValue: [this.$valid.selectRequired('设备/设施类型')],
- deviceIds: this.$valid.custome({
- validator(rule, value, cb) {
- const rl = rule;
- if (!value.length) {
- rl.message = '已选列表不能为空';
- cb(new Error());
- } else {
- cb();
- }
- }
- })
- },
- formCols: [
- [
- {
- label: '所属社区',
- prop: 'communityId',
- slot: 'communityId'
- },
- {
- label: '巡检计划名称',
- prop: 'inspectionName',
- input: true
- },
- {
- label: '设备/设施类型',
- prop: 'typeValue',
- slot: 'typeValue'
- },
- {
- label: '',
- prop: 'deviceIds',
- slot: 'deviceIds'
- },
- {
- label: '巡检时间',
- prop: 'startDate',
- slot: 'startDate'
- },
- {
- label: '巡检人员',
- prop: 'peopleId',
- slot: 'peopleId'
- },
- {
- label: '拍照要求',
- prop: 'cameraSettings',
- slot: 'cameraSettings'
- },
- {
- label: ' 备注信息',
- prop: 'remark',
- maxlength: '100',
- rows: 3,
- textarea: true
- }
- ]
- ],
- findUser: [],
- deviceArr: [],
- devicesArr: [],
- defaultProps: {
- value: 'id', // 唯一标识
- label: 'label', // 标签显示
- children: 'children'
- },
- defaultProps1: {
- value: 'id', // 唯一标识
- label: 'label', // 标签显示
- children: 'children',
- emitPath: false
- },
- typeValueKey: 0,
- typeValueW: [],
- effectiveDate: []
- };
- },
- methods: {
- submit() {
- new Promise((resolve) => {
- this.$refs.form.validate(resolve);
- }).then(() => {
- var loading = this.$loading();
- let url = '/sc-community/inspection/add';
- let initData = JSON.parse(JSON.stringify(this.formData));
- if (this.params.todo === 'edit') {
- url = '/sc-community/inspection/update';
- }
- this.$http
- .post(url, initData)
- .then(({ status, msg }) => {
- if (status == 0) {
- this.$message.success(msg);
- this.params.callback();
- this.$emit('close');
- } else {
- this.$message.error(msg);
- }
- loading.close();
- })
- .catch(() => {
- loading.close();
- });
- });
- },
- findUserToggle() {
- this.formData.peopleName = this.$refs.userName.getCheckedNodes()[0].label;
- },
- deviceArrToggle() {
- this.formData.typeValue = this.typeValueW[this.typeValueW.length - 1];
- if (!!this.formData.typeValue) {
- this.formData.type = this.$refs.typeValue.getCheckedNodes()[0].data.type;
- }
- this.getTypes();
- },
- getTypes() {
- this.$http
- .get('/sc-community/inspection/getDevices', {
- type: this.formData.type,
- typeId: this.formData.typeValue,
- communityId: this.formData.communityId
- })
- .then(({ data, msg }) => {
- this.devicesArr = data || [];
- });
- },
- handleChange(e) {
- if (!!this.formData.typeValue) {
- this.formData.typeValue = '';
- this.formData.type = '';
- this.typeValueKey++;
- this.getTypes();
- }
- },
- effectiveDateToggle(va) {
- let arr = va;
- if (!arr) {
- arr = ['', ''];
- }
- this.formData.startDate = arr[0] + '00:00:00';
- this.formData.endDate = arr[1] + '23:59:59';
- },
- getDetails(id, resolve) {
- this.$http.get('/sc-community/inspection/find/' + id).then(({ data, msg }) => {
- const {
- communityId,
- inspectionName,
- cameraSettings,
- peopleId,
- peopleName,
- startDate,
- endDate,
- remark,
- type,
- typeValue,
- id
- } = data;
- this.formData = {
- communityId: communityId,
- inspectionName: inspectionName,
- cameraSettings: cameraSettings,
- peopleId: peopleId,
- peopleName: peopleName,
- startDate: startDate,
- endDate: endDate,
- deviceIds: [],
- type: type,
- typeValue: typeValue,
- remark: remark,
- id: id
- };
- this.typeValueW = typeValue;
- this.effectiveDate = [data.startDate, data.endDate];
- resolve && resolve(true);
- });
- },
- getSelectDevice(id) {
- this.$http.get('/sc-community/inspection/getInspectionDevices?id=' + id).then(({ data, msg }) => {
- if (!!data && data.length > 0) {
- let deviceIds = [];
- data.map((item) => {
- deviceIds.push(item.deviceId);
- });
- this.formData.deviceIds = deviceIds;
- }
- });
- }
- },
- created() {
- this.deviceArr = this.params.deviceArr;
- this.findUser = this.params.arrData;
- if (!!this.params.data && !!this.params.data.id) {
- new Promise((resolve) => {
- this.getDetails(this.params.data.id, resolve);
- }).then((_) => {
- this.getTypes();
- this.getSelectDevice(this.params.data.id);
- });
- }
- }
- };
- </script>
- <style scoped lang='scss' scoped>
- /deep/ .el-date-editor .el-range-separator {
- padding: 0;
- }
- </style>
|