add.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <zz-form :cols="formCols" :data="formData" :rules="formRules" labelWidth="120" ref="form">
  3. <template slot="communityId">
  4. <el-select class="width65" v-model="formData.communityId" clearable>
  5. <el-option
  6. :label="item.communityName"
  7. :value="item.id"
  8. v-for="item in $store.getters['getAreaSelect']"
  9. :key="item.id"
  10. ></el-option>
  11. </el-select>
  12. </template>
  13. <template slot="cameraSettings">
  14. <el-select class="width65" v-model="formData.cameraSettings" clearable>
  15. <el-option label="是" :value="1"></el-option>
  16. <el-option label="否" :value="0"></el-option>
  17. </el-select>
  18. </template>
  19. <template slot="typeValue">
  20. <el-cascader
  21. ref="typeValue"
  22. v-model="formData.typeValue"
  23. :props="defaultProps"
  24. :options="deviceArr"
  25. @change="deviceArrToggle"
  26. ></el-cascader>
  27. <div style="text-align: center; margin-top: 20px">
  28. <el-transfer
  29. style="text-align: left; display: inline-block"
  30. v-model="formData.deviceIds"
  31. filterable
  32. :props="{
  33. key: 'id',
  34. label: 'deviceName'
  35. }"
  36. :titles="['待选列表', '已选列表']"
  37. @change="handleChange"
  38. :data="devicesArr"
  39. ></el-transfer>
  40. </div>
  41. </template>
  42. <el-date-picker
  43. class="width100"
  44. slot="startDate"
  45. v-model="effectiveDate"
  46. value-format="yyyy-MM-dd "
  47. type="daterange"
  48. range-separator="至"
  49. start-placeholder="选择开始日期"
  50. end-placeholder="选择结束日期"
  51. @change="effectiveDateToggle"
  52. :editable="false"
  53. ></el-date-picker>
  54. <el-cascader
  55. ref="userName"
  56. v-model="formData.peopleId"
  57. :props="defaultProps"
  58. slot="peopleId"
  59. :options="findUser"
  60. @change="findUserToggle"
  61. ></el-cascader>
  62. </zz-form>
  63. </template>
  64. <script >
  65. export default {
  66. props: ['params'],
  67. data() {
  68. return {
  69. formData: {
  70. communityId: '',
  71. inspectionName: '',
  72. cameraSettings: '',
  73. peopleId: '',
  74. peopleName: '',
  75. startDate: '',
  76. endDate: '',
  77. deviceIds: [],
  78. type: '',
  79. typeValue: '',
  80. remark: ''
  81. },
  82. formRules: {
  83. communityId: [this.$valid.selectRequired('社区')],
  84. peopleId: [this.$valid.selectRequired('巡检人员')],
  85. startDate: [this.$valid.selectRequired('巡检时间')],
  86. inspectionName: [this.$valid.inputRequired('巡检计划名称')],
  87. address: this.$valid.custome({
  88. validator(rule, value, cb) {
  89. const rl = rule;
  90. let regExp = /^.{1,20}$/;
  91. if (!value) {
  92. rl.message = '请输入地址';
  93. cb(new Error());
  94. } else if (!regExp.test(value)) {
  95. rl.message = '不能超过20个字';
  96. cb(new Error());
  97. } else {
  98. cb();
  99. }
  100. }
  101. }),
  102. repairName: this.$valid.custome({
  103. validator(rule, value, cb) {
  104. const rl = rule;
  105. let regExp = /^.{1,20}$/;
  106. if (!value) {
  107. rl.message = '请输入报修人';
  108. cb(new Error());
  109. } else if (!regExp.test(value)) {
  110. rl.message = '不能超过20个字';
  111. cb(new Error());
  112. } else {
  113. cb();
  114. }
  115. }
  116. }),
  117. typeValue: [this.$valid.selectRequired('设备/设施类型')]
  118. },
  119. formCols: [
  120. [
  121. {
  122. label: '所属社区',
  123. prop: 'communityId',
  124. slot: 'communityId'
  125. },
  126. {
  127. label: '巡检计划名称',
  128. prop: 'inspectionName',
  129. input: true
  130. },
  131. {
  132. label: '设备/设施类型',
  133. prop: 'typeValue',
  134. slot: 'typeValue'
  135. },
  136. {
  137. label: '巡检时间',
  138. prop: 'startDate',
  139. slot: 'startDate'
  140. },
  141. {
  142. label: '巡检人员',
  143. prop: 'peopleId',
  144. slot: 'peopleId'
  145. },
  146. {
  147. label: '拍照要求',
  148. prop: 'cameraSettings',
  149. slot: 'cameraSettings'
  150. },
  151. {
  152. label: ' 备注信息',
  153. prop: 'remark',
  154. maxlength: '100',
  155. rows: 3,
  156. textarea: true
  157. }
  158. ]
  159. ],
  160. findUser: [],
  161. deviceArr: [],
  162. devicesArr: [],
  163. defaultProps: {
  164. value: 'id', // 唯一标识
  165. label: 'label', // 标签显示
  166. children: 'children',
  167. emitPath: false
  168. },
  169. effectiveDate: []
  170. };
  171. },
  172. methods: {
  173. submit() {
  174. new Promise(resolve => {
  175. this.$refs.form.validate(resolve);
  176. }).then(() => {
  177. var loading = this.$loading();
  178. let url = '/sc-community/inspection/add';
  179. if (this.params.todo === 'edit') {
  180. url = '/sc-community/inspection/update';
  181. }
  182. let initData = JSON.parse(JSON.stringify(this.formData));
  183. // initData.startDate = this.formData.startDate + '00:00:00';
  184. // initData.endDate = this.formData.endDate + '23:59:59';
  185. this.$http
  186. .post(url, initData)
  187. .then(({ status, msg }) => {
  188. if (status == 0) {
  189. this.$message.success(msg);
  190. this.params.callback();
  191. this.$emit('close');
  192. } else {
  193. this.$message.error(msg);
  194. }
  195. loading.close();
  196. })
  197. .catch(() => {
  198. loading.close();
  199. });
  200. });
  201. },
  202. findUserToggle() {
  203. this.formData.peopleName = this.$refs.userName.getCheckedNodes()[0].label;
  204. },
  205. deviceArrToggle() {
  206. this.formData.type = this.$refs.typeValue.getCheckedNodes()[0].data.type;
  207. this.getTypes();
  208. },
  209. getTypes() {
  210. this.$http
  211. .get('/sc-community/inspection/getDevices', { type: this.formData.type, typeId: this.formData.typeValue })
  212. .then(({ data, msg }) => {
  213. this.devicesArr = data;
  214. });
  215. },
  216. handleChange(e) {
  217. console.log(this.rightChecked);
  218. },
  219. effectiveDateToggle(va) {
  220. let arr = va;
  221. if (!arr) {
  222. arr = ['', ''];
  223. }
  224. this.formData.startDate = arr[0];
  225. this.formData.endDate = arr[1];
  226. },
  227. getDetails(id, resolve) {
  228. this.$http.get('/sc-community/inspection/find/' + id).then(({ data, msg }) => {
  229. const {
  230. communityId,
  231. inspectionName,
  232. cameraSettings,
  233. peopleId,
  234. peopleName,
  235. startDate,
  236. endDate,
  237. remark,
  238. type,
  239. typeValue,
  240. id
  241. } = data;
  242. this.formData = {
  243. communityId: communityId,
  244. inspectionName: inspectionName,
  245. cameraSettings: cameraSettings,
  246. peopleId: peopleId,
  247. peopleName: peopleName,
  248. startDate: startDate,
  249. endDate: endDate,
  250. deviceIds: [],
  251. type: type,
  252. typeValue: typeValue,
  253. remark: remark,
  254. id: id
  255. };
  256. this.effectiveDate = [data.startDate, data.endDate];
  257. resolve && resolve(true);
  258. });
  259. },
  260. getSelectDevice(id) {
  261. this.$http.get('/sc-community/inspection/getInspectionDevices?id=' + id).then(({ data, msg }) => {
  262. if (!!data && data.length > 0) {
  263. let deviceIds = [];
  264. data.map(item => {
  265. deviceIds.push(item.deviceId);
  266. });
  267. this.formData.deviceIds = deviceIds;
  268. }
  269. });
  270. }
  271. },
  272. created() {
  273. this.deviceArr = this.params.deviceArr;
  274. this.findUser = this.params.arrData;
  275. if (!!this.params.data && !!this.params.data.id) {
  276. new Promise(resolve => {
  277. this.getDetails(this.params.data.id, resolve);
  278. }).then(_ => {
  279. this.getTypes();
  280. this.getSelectDevice(this.params.data.id);
  281. });
  282. }
  283. }
  284. };
  285. </script>
  286. <style scoped lang='scss' scoped>
  287. /deep/ .el-date-editor .el-range-separator {
  288. padding: 0;
  289. }
  290. </style>