add.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 @change="handleChange">
  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. :key="typeValueKey"
  22. ref="typeValue"
  23. v-model="typeValueW"
  24. :props="defaultProps"
  25. :options="deviceArr"
  26. @change="deviceArrToggle"
  27. ></el-cascader>
  28. <div style="text-align: center; margin-top: 20px">
  29. <el-transfer
  30. style="text-align: left; display: inline-block"
  31. v-model="formData.deviceIds"
  32. filterable
  33. :props="{
  34. key: 'id',
  35. label: 'deviceName'
  36. }"
  37. :titles="['待选列表', '已选列表']"
  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="defaultProps1"
  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. },
  168. defaultProps1: {
  169. value: 'id', // 唯一标识
  170. label: 'label', // 标签显示
  171. children: 'children',
  172. emitPath: false
  173. },
  174. typeValueKey: 0,
  175. typeValueW: [],
  176. effectiveDate: []
  177. };
  178. },
  179. methods: {
  180. submit() {
  181. new Promise((resolve) => {
  182. this.$refs.form.validate(resolve);
  183. }).then(() => {
  184. var loading = this.$loading();
  185. let url = '/sc-community/inspection/add';
  186. let initData = JSON.parse(JSON.stringify(this.formData));
  187. if (this.params.todo === 'edit') {
  188. url = '/sc-community/inspection/update';
  189. }
  190. this.$http
  191. .post(url, initData)
  192. .then(({ status, msg }) => {
  193. if (status == 0) {
  194. this.$message.success(msg);
  195. this.params.callback();
  196. this.$emit('close');
  197. } else {
  198. this.$message.error(msg);
  199. }
  200. loading.close();
  201. })
  202. .catch(() => {
  203. loading.close();
  204. });
  205. });
  206. },
  207. findUserToggle() {
  208. this.formData.peopleName = this.$refs.userName.getCheckedNodes()[0].label;
  209. },
  210. deviceArrToggle() {
  211. this.formData.typeValue = this.typeValueW[this.typeValueW.length - 1];
  212. if (!!this.formData.typeValue) {
  213. this.formData.type = this.$refs.typeValue.getCheckedNodes()[0].data.type;
  214. }
  215. this.getTypes();
  216. },
  217. getTypes() {
  218. this.$http
  219. .get('/sc-community/inspection/getDevices', {
  220. type: this.formData.type,
  221. typeId: this.formData.typeValue,
  222. communityId: this.formData.communityId
  223. })
  224. .then(({ data, msg }) => {
  225. this.devicesArr = data || [];
  226. });
  227. },
  228. handleChange(e) {
  229. if (!!this.formData.typeValue) {
  230. this.formData.typeValue = '';
  231. this.formData.type = '';
  232. this.typeValueKey++;
  233. this.getTypes();
  234. }
  235. },
  236. effectiveDateToggle(va) {
  237. let arr = va;
  238. if (!arr) {
  239. arr = ['', ''];
  240. }
  241. this.formData.startDate = arr[0] + '00:00:00';
  242. this.formData.endDate = arr[1] + '23:59:59';
  243. },
  244. getDetails(id, resolve) {
  245. this.$http.get('/sc-community/inspection/find/' + id).then(({ data, msg }) => {
  246. const {
  247. communityId,
  248. inspectionName,
  249. cameraSettings,
  250. peopleId,
  251. peopleName,
  252. startDate,
  253. endDate,
  254. remark,
  255. type,
  256. typeValue,
  257. id
  258. } = data;
  259. this.formData = {
  260. communityId: communityId,
  261. inspectionName: inspectionName,
  262. cameraSettings: cameraSettings,
  263. peopleId: peopleId,
  264. peopleName: peopleName,
  265. startDate: startDate,
  266. endDate: endDate,
  267. deviceIds: [],
  268. type: type,
  269. typeValue: typeValue,
  270. remark: remark,
  271. id: id
  272. };
  273. this.typeValueW = typeValue;
  274. this.effectiveDate = [data.startDate, data.endDate];
  275. resolve && resolve(true);
  276. });
  277. },
  278. getSelectDevice(id) {
  279. this.$http.get('/sc-community/inspection/getInspectionDevices?id=' + id).then(({ data, msg }) => {
  280. if (!!data && data.length > 0) {
  281. let deviceIds = [];
  282. data.map((item) => {
  283. deviceIds.push(item.deviceId);
  284. });
  285. this.formData.deviceIds = deviceIds;
  286. }
  287. });
  288. }
  289. },
  290. created() {
  291. this.deviceArr = this.params.deviceArr;
  292. this.findUser = this.params.arrData;
  293. if (!!this.params.data && !!this.params.data.id) {
  294. new Promise((resolve) => {
  295. this.getDetails(this.params.data.id, resolve);
  296. }).then((_) => {
  297. this.getTypes();
  298. this.getSelectDevice(this.params.data.id);
  299. });
  300. }
  301. }
  302. };
  303. </script>
  304. <style scoped lang='scss' scoped>
  305. /deep/ .el-date-editor .el-range-separator {
  306. padding: 0;
  307. }
  308. </style>