addDialogCom.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div>
  3. <!-- <div>{{ datas }}</div>
  4. <br />
  5. <div>{{ sourceTypeList }}</div> -->
  6. <el-row>
  7. <el-col :span="14">
  8. <el-row>
  9. <el-col :span="24">
  10. <el-radio-group v-model="weekDay">
  11. <el-radio-button label="1">星期一</el-radio-button>
  12. <el-radio-button label="2">星期二</el-radio-button>
  13. <el-radio-button label="3">星期三</el-radio-button>
  14. <el-radio-button label="4">星期四</el-radio-button>
  15. <el-radio-button label="5">星期五</el-radio-button>
  16. <el-radio-button label="6">星期六</el-radio-button>
  17. <el-radio-button label="7">星期日</el-radio-button>
  18. </el-radio-group>
  19. </el-col>
  20. </el-row>
  21. </el-col>
  22. <el-col :span="10">
  23. <el-row type="flex" justify="end">
  24. <el-col :span="11">
  25. <el-button type="primary" size="medium" @click="addBtnClick">新增规则</el-button>&nbsp;&nbsp;
  26. <el-popover placement="bottom" title="复制到" trigger="click" @show="copyToPanelShow" v-model="copyToPanelVisible">
  27. <div class="copytoPanel">
  28. <el-card>
  29. <el-checkbox-group v-model="copyToSelects">
  30. <el-checkbox label="1">周一</el-checkbox>
  31. <el-checkbox label="2">周二</el-checkbox>
  32. <el-checkbox label="3">周三</el-checkbox>
  33. <el-checkbox label="4">周四</el-checkbox>
  34. <el-checkbox label="5">周五</el-checkbox>
  35. <el-checkbox label="6">周六</el-checkbox>
  36. <el-checkbox label="7">周日</el-checkbox>
  37. </el-checkbox-group>
  38. <br />
  39. <el-button type="primary" @click="copyToClick">复制</el-button>
  40. </el-card>
  41. </div>
  42. <el-button slot="reference" type="primary">复制到</el-button>
  43. </el-popover>
  44. </el-col>
  45. </el-row>
  46. </el-col>
  47. </el-row>
  48. <el-empty
  49. v-if="datas[sourceType] == undefined || datas[sourceType][weekDay] == undefined || datas[sourceType][weekDay].length == 0"
  50. description="未找到数据"></el-empty>
  51. <div v-else v-for="(item, index) in datas[sourceType][weekDay]" :key="item" class="ruleDiv">
  52. <div class="sonruleDiv">
  53. <el-time-picker placeholder="开始时间" value-format="HH:mm:ss" v-model="item.times" is-range range-separator="至"
  54. @input="timeInput(item.times)" clearable=false clear-icon="">
  55. </el-time-picker>&nbsp;&nbsp;
  56. <el-select v-model="item.fieldcode" placholeder="请选择属性" @change="sourceTypeItemChanged(item, item.fieldcode)">
  57. <el-option v-for="sourceTypeItem in sourceTypeList" :key="sourceTypeItem.sysFieldCode"
  58. :label="sourceTypeItem.name" :value="sourceTypeItem.sysFieldCode">
  59. </el-option>
  60. </el-select>&nbsp;&nbsp;
  61. <el-select v-model="item.operator" placeholder="请选择操作" @change="operatorChanged(item, item.operator)">
  62. <el-option v-for="operatorsItem in item.operators" :key="operatorsItem.key" :label="operatorsItem.value"
  63. :value="operatorsItem.key">
  64. </el-option>
  65. </el-select>&nbsp;&nbsp;
  66. <el-input-number v-if="item.sourceValues == undefined || item.sourceValues.length==0"
  67. v-model="item.value" :precision="2" :step="0.1" @change="onInputChange" ></el-input-number>
  68. <el-select v-else v-model="item.value" placeholder="请选择操作" @change="valueChanged(item, item.value)">
  69. <el-option v-for="sourceValueItem in item.sourceValues" :key="sourceValueItem.key"
  70. :label="sourceValueItem.value" :value="sourceValueItem.key"
  71. @click.native="sourceValueItemClick(sourceValueItem, item)">
  72. </el-option>
  73. </el-select>&nbsp;&nbsp;
  74. <el-button type="primary" @click.native="removeClick(item, index)">移除</el-button>
  75. </div>
  76. </div>
  77. </div>
  78. </template>
  79. <script>
  80. export default {
  81. props: {
  82. sourceType: String,
  83. datas: Object,
  84. sourceTypeList: Array,
  85. },
  86. name: "SocWebAddDialogCom",
  87. data() {
  88. return {
  89. weekDay: "1",
  90. copyToSelects: [],
  91. copyToPanelVisible:false
  92. };
  93. },
  94. mounted() { },
  95. methods: {
  96. addBtnClick() {
  97. if (this.datas[this.sourceType] == undefined) {
  98. this.datas[this.sourceType] = {};
  99. }
  100. if (this.datas[this.sourceType][this.weekDay] == undefined) {
  101. this.datas[this.sourceType][this.weekDay] = [];
  102. }
  103. let weekDayDatas = this.datas[this.sourceType][this.weekDay];
  104. let newData = {
  105. id: "",
  106. ruleId: "",
  107. fieldcode: "",
  108. //@ApiModelProperty(value = "操作符,GT(大于)、GTE(大于等于)、LT(小于)、LTE(小于等 于)、EQUALS(等于)、STARTS_WITH(以什么开始)、 ENDS_WITH(以什么结束)、CONTAIN(包含)")
  109. operator: "",
  110. value: "",
  111. valueText: "",
  112. //@ApiModelProperty(value = "报警源类型:4:烟雾传感器;5: 温湿度采集器;6:水浸; 7:门磁、窗磁;8:卷帘门门磁;9:地磁;10燃气报警器;20:报警防区")
  113. sourceType: this.sourceType,
  114. //@ApiModelProperty(value = "规则使用周期:1.周一,2.周二,3.周三,4.周四,5.周五,6.周六,7.周日")
  115. weekDay: this.weekDay,
  116. startTime: "00:00:00",
  117. endTime: "23:59:59",
  118. times: ["00:00:00", "23:59:59"]
  119. };
  120. if (newData.fieldcode == undefined || newData.fieldcode == "") {
  121. if (this.sourceTypeList != undefined && this.sourceTypeList.length > 0) {
  122. newData.fieldcode = this.sourceTypeList[0].sysFieldCode;
  123. }
  124. }
  125. if (newData.operator == undefined || newData.operator == "") {
  126. if (this.sourceTypeList != undefined && this.sourceTypeList.length > 0
  127. && this.sourceTypeList[0].operatorsList != undefined
  128. && this.sourceTypeList[0].operatorsList.length > 0) {
  129. newData.operator = this.sourceTypeList[0].operatorsList[0].key
  130. }
  131. }
  132. if (newData.value == undefined || newData.value == "") {
  133. if (this.sourceTypeList != undefined && this.sourceTypeList.length > 0
  134. && this.sourceTypeList[0].specsList != undefined
  135. && this.sourceTypeList[0].specsList.length > 0) {
  136. newData.value = this.sourceTypeList[0].specsList[0].key
  137. newData.valueText = this.sourceTypeList[0].specsList[0].value;
  138. }
  139. }
  140. this.initDataItem(newData, newData.fieldcode);
  141. weekDayDatas.push(newData);
  142. this.$forceUpdate();
  143. },
  144. copyToClick() {
  145. if (this.copyToSelects.length == 0) {
  146. this.$message({ message: "请选择需要复制到的星期!", type: 'warning' });
  147. return;
  148. }
  149. if (this.datas[this.sourceType] == undefined ||
  150. this.datas[this.sourceType][this.weekDay] == undefined ||
  151. this.datas[this.sourceType][this.weekDay].length == 0) {
  152. this.$message({ message: "没有可复制的数据", type: 'warning' });
  153. return;
  154. }
  155. this.copyToSelects.forEach(i => {
  156. let tempData = JSON.stringify(this.datas[this.sourceType][this.weekDay]);
  157. let newData = JSON.parse(tempData);
  158. newData.forEach(newDataItem => {
  159. newDataItem.weekDay=i;
  160. })
  161. this.datas[this.sourceType][i] = newData;
  162. });
  163. this.copyToPanelVisible = false;
  164. this.$forceUpdate();
  165. return true;
  166. },
  167. sourceTypeItemChanged(item, type) {
  168. this.initDataItem(item, type);
  169. this.$forceUpdate();
  170. },
  171. initDataItem(item, type) {
  172. let exist = this.sourceTypeList.find(i => i.sysFieldCode == type)
  173. if (exist == undefined) {
  174. item.operators = [];
  175. item.sourceValues = [];
  176. }
  177. else {
  178. item.operators = exist.operatorsList;
  179. item.sourceValues = exist.specsList;
  180. }
  181. return item;
  182. },
  183. operatorChanged(item, value) {
  184. this.$forceUpdate();
  185. },
  186. valueChanged(item, value) {
  187. this.$forceUpdate();
  188. },
  189. timeInput(value) {
  190. this.$forceUpdate();
  191. },
  192. onInputChange()
  193. {
  194. this.$forceUpdate();
  195. },
  196. removeClick(item, index) {
  197. if (this.datas[this.sourceType] == undefined) {
  198. this.datas[this.sourceType] = {};
  199. }
  200. if (this.datas[this.sourceType][this.weekDay] == undefined) {
  201. this.datas[this.sourceType][this.weekDay] = [];
  202. }
  203. let weekDayDatas = this.datas[this.sourceType][this.weekDay];
  204. if (weekDayDatas.length > index) {
  205. weekDayDatas.splice(index, 1)
  206. this.$forceUpdate();
  207. }
  208. },
  209. sourceValueItemClick(sourceValueItem, item) {
  210. console.log(sourceValueItem, item);
  211. },
  212. copyToPanelShow() {
  213. this.copyToSelects = [];
  214. }
  215. },
  216. };
  217. </script>
  218. <style lang="scss" scoped>
  219. .ruleDiv {
  220. margin-top: 20px;
  221. .sonruleDiv {
  222. margin-top: 10px;
  223. .el-button {
  224. margin-left: 20px;
  225. }
  226. }
  227. }
  228. .copytoPanel {
  229. .el-checkbox {
  230. width: 50px;
  231. margin-top: 10px;
  232. }
  233. }
  234. </style>