automation.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <view class="automation">
  3. <custom-card>
  4. <block slot="backText">自动控制</block>
  5. </custom-card>
  6. <view
  7. class="automation-content"
  8. :class="{ 'automation-content-rever': activeIndex === 1 }"
  9. >
  10. <view class="automation-header">
  11. <view
  12. class="automation-header-item"
  13. :class="{ 'automation-header-item-active': activeIndex === 0 }"
  14. @click="clickHeaderItem(0)"
  15. >灌溉
  16. <view
  17. :class="
  18. activeIndex == '0'
  19. ? 'automation-header-item-icon'
  20. : 'automation-header-item-icon-bottom'
  21. "
  22. ></view>
  23. </view>
  24. <view
  25. class="automation-header-item"
  26. @click="clickHeaderItem(1)"
  27. :class="{ 'automation-header-item-active': activeIndex === 1 }"
  28. >水肥
  29. <view
  30. :class="
  31. activeIndex == '1'
  32. ? 'automation-header-item-icon'
  33. : 'automation-header-item-icon-bottom'
  34. "
  35. ></view>
  36. </view>
  37. </view>
  38. <view class="automation-body">
  39. <rotation-items
  40. :formData="formData"
  41. :tktype="tktype"
  42. @formDataHandler="updateFormData"
  43. />
  44. <view class="automation-body-title">灌区选择</view>
  45. <rotation-bottom
  46. :activeIndex="activeIndex"
  47. :irrigatedAreaList="irrigatedAreaList"
  48. :alreadyList="alreadyList"
  49. @updateList="updateListHandler"
  50. :tktype="tktype"
  51. />
  52. </view>
  53. </view>
  54. <view class="automation-footer">
  55. <view class="automation-footer-left">
  56. 已选<text class="automation-footer-left-num">{{ selectNum }}</text
  57. >个灌区
  58. </view>
  59. <view class="automation-footer-right" @click="immediateExecution"
  60. >立即执行</view
  61. >
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import rotationItems from './components/rotationItems.vue';
  67. import rotationBottom from './components/rotationBottom.vue';
  68. export default {
  69. name: 'automation',
  70. data() {
  71. return {
  72. activeIndex: 0,
  73. devBid: '',
  74. devName: '',
  75. devStatus: '',
  76. irrigatedAreaList: [],
  77. alreadyList: [],
  78. formData: {
  79. lgjg: '',
  80. fqcx: '',
  81. fhcx: '',
  82. lgcs: 1,
  83. },
  84. tktype: 1,
  85. selectNum: 0,
  86. };
  87. },
  88. components: {
  89. rotationBottom,
  90. rotationItems,
  91. },
  92. watch: {
  93. alreadyList: {
  94. handler(val) {
  95. this.selectNum = 0;
  96. val.forEach((item) => {
  97. if (item.isChecked) {
  98. this.selectNum++;
  99. }
  100. });
  101. },
  102. deep: true,
  103. immediate: true,
  104. },
  105. },
  106. onLoad(options) {
  107. this.devBid = options.devBid;
  108. this.devName = options.devName;
  109. this.devStatus = options.devStatus;
  110. },
  111. methods: {
  112. updateListHandler(list) {
  113. this.alreadyList = list;
  114. },
  115. updateFormData(options) {
  116. this.formData[options.key] = options.value;
  117. },
  118. async getAlreadyList() {
  119. const res = await this.$myRequest({
  120. url: '/api/v2/iot/mobile/device/fkq/group/already/list/',
  121. method: 'post',
  122. data: {
  123. devBid: this.devBid,
  124. },
  125. });
  126. console.log(res, '-------------------- get already list');
  127. res?.forEach((item) => {
  128. item.isChecked = false;
  129. });
  130. this.alreadyList = res;
  131. },
  132. async getdeviceSfStatus() {
  133. const res = await this.$myRequest({
  134. url: '/api/v2/iot/mobile/device/fkq/status/',
  135. method: 'post',
  136. data: {
  137. devBid: this.devBid,
  138. },
  139. });
  140. this.dataList = [];
  141. this.irrigatedAreaList = [];
  142. this.alreadyfertilizerBucketList = [];
  143. console.log('get device sf status', res);
  144. res.forEach((item) => {
  145. if (item.sfType === '7') {
  146. this.irrigatedAreaList.push(item);
  147. }
  148. });
  149. },
  150. clickHeaderItem(index) {
  151. this.activeIndex = index;
  152. this.tktype = index == 0 ? 1 : 2;
  153. },
  154. // iot/mobile/device/fkq/zsrf/task/ctl/
  155. async postTaskCtl(payload) {
  156. // loading
  157. uni.showLoading({
  158. title: '正在执行',
  159. });
  160. console.log(payload, 'payloadpayload');
  161. const res = await this.$myRequest({
  162. url: '/api/v2/iot/mobile/device/fkq/zsrf/task/ctl/',
  163. method: 'post',
  164. data: payload,
  165. header: {
  166. 'Content-Type': 'application/json',
  167. },
  168. });
  169. uni.hideLoading();
  170. console.log(res, 'resresres');
  171. if (res?.code === '000000') {
  172. uni.showToast({
  173. title: '操作成功',
  174. });
  175. setTimeout(() => {
  176. uni.redirectTo({
  177. url: `/pages/cb/zhamenFirst/rotationflow?devBid=${this.devBid}&devName=${this.devName}&devStatus=${this.devStatus}`,
  178. });
  179. }, 1000);
  180. } else {
  181. uni.showToast({
  182. icon: 'none',
  183. title: res.msg,
  184. });
  185. }
  186. },
  187. immediateExecution() {
  188. console.log(this.formData, 'formDataformDataformData');
  189. if (!this.formData['lgjg']) {
  190. uni.showToast({
  191. title: '请输入轮灌间隔时间',
  192. icon: 'none',
  193. });
  194. return;
  195. }
  196. if (this.tktype == 2 && !this.formData['fqcx']) {
  197. uni.showToast({
  198. title: '请输入肥前水时间',
  199. icon: 'none',
  200. });
  201. return;
  202. }
  203. if (this.tktype == 2 && !this.formData['fhcx']) {
  204. uni.showToast({
  205. title: '请输入肥后水时间',
  206. icon: 'none',
  207. });
  208. return;
  209. }
  210. if (this.tktype == 2 && !this.formData['sfmode']) {
  211. uni.showToast({
  212. title: '请选择模式',
  213. icon: 'none',
  214. });
  215. return;
  216. }
  217. if (this.selectNum === 0) {
  218. uni.showToast({
  219. title: '请选择灌区',
  220. icon: 'none',
  221. });
  222. return;
  223. }
  224. const fqList = [];
  225. for (let i = 0; i < this.alreadyList.length; i++) {
  226. const item = this.alreadyList[i];
  227. if (item.isChecked && !item.ti) {
  228. uni.showToast({
  229. title: `请输入${item.sfDisplayname || item.sfName}的时长`,
  230. icon: 'none',
  231. });
  232. return;
  233. } else if (item.isChecked && this.tktype == 2 && !item.pfCode) {
  234. uni.showToast({
  235. title: `请输入${item.sfDisplayname || item.sfName}的配方`,
  236. icon: 'none',
  237. });
  238. return;
  239. }
  240. if (item.isChecked) {
  241. fqList.push({
  242. fqCode: item.sfCode,
  243. ti: item.ti || '',
  244. pfCode: item.pfCode || '',
  245. });
  246. }
  247. }
  248. const payload = {
  249. devBid: this.devBid,
  250. tktype: this.tktype,
  251. tkid: 0,
  252. status: 1,
  253. ...this.formData,
  254. fqList,
  255. sfmode: this.tktype !== 1 ? this.formData.sfmode || 1 : '',
  256. };
  257. this.postTaskCtl(payload);
  258. },
  259. },
  260. };
  261. </script>
  262. <style scoped lang="scss">
  263. uni-page-body,
  264. uni-page-wrapper {
  265. position: relative;
  266. height: 100%;
  267. }
  268. .automation {
  269. background: linear-gradient(180deg, #ffffff00 0%, #fff 23.64%, #fff 100%),
  270. linear-gradient(102deg, #bfeadd 6.77%, #b8f1e7 40.15%, #b9eef5 84.02%);
  271. width: 100%;
  272. height: calc(100% - 100rpx);
  273. overflow: hidden;
  274. .automation-content {
  275. border-bottom: none;
  276. border-radius: 16rpx 16rpx 0 0;
  277. position: relative;
  278. overflow: hidden;
  279. &::before {
  280. position: absolute;
  281. content: '';
  282. top: 0;
  283. left: 0;
  284. right: 0;
  285. bottom: 0;
  286. background: url('https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/newindex/controlbg.png')
  287. no-repeat;
  288. background-size: cover;
  289. }
  290. }
  291. .automation-content-rever {
  292. border-bottom: none;
  293. border-radius: 16rpx 16rpx 0 0;
  294. position: relative;
  295. &::before {
  296. position: absolute;
  297. content: '';
  298. top: 0;
  299. left: 0;
  300. right: 0;
  301. bottom: 0;
  302. background: url('https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/newindex/controlbg.png')
  303. no-repeat;
  304. background-size: cover;
  305. transform: rotateY(180deg);
  306. transform-origin: center center;
  307. }
  308. }
  309. .automation-header {
  310. width: 100%;
  311. display: flex;
  312. .automation-header-item {
  313. width: 50%;
  314. height: 80rpx;
  315. display: flex;
  316. justify-content: center;
  317. align-items: center;
  318. font-size: 36rpx;
  319. color: #687a74;
  320. text-align: center;
  321. font-family: 'Source Han Sans CN VF';
  322. font-size: 32rpx;
  323. font-weight: 400;
  324. position: relative;
  325. }
  326. .automation-header-item-active {
  327. color: #042118;
  328. text-align: center;
  329. font-family: 'Source Han Sans CN VF';
  330. font-size: 32rpx;
  331. font-weight: 500;
  332. position: relative;
  333. }
  334. .automation-header-item-icon {
  335. width: 28rpx;
  336. height: 4rpx;
  337. border-radius: 4rpx;
  338. background-color: #14a478;
  339. position: absolute;
  340. bottom: 0;
  341. }
  342. .automation-header-item-icon-bottom {
  343. background-color: transparent;
  344. }
  345. }
  346. .automation-body {
  347. height: calc(100vh - 250rpx);
  348. overflow: hidden;
  349. .automation-body-title {
  350. position: relative;
  351. color: #042118;
  352. font-family: 'Source Han Sans CN VF';
  353. font-size: 28rpx;
  354. font-weight: 500;
  355. margin: 48rpx 32rpx 16rpx 32rpx;
  356. }
  357. }
  358. .automation-footer {
  359. position: fixed;
  360. width: 100%;
  361. padding: 16rpx 0;
  362. background: #fff;
  363. box-shadow: 0 -4rpx 8rpx 0 #0000001a;
  364. bottom: 0;
  365. height: 80rpx;
  366. display: flex;
  367. justify-content: space-between;
  368. align-items: center;
  369. .automation-footer-left {
  370. width: 50%;
  371. margin-left: 32rpx;
  372. color: #9ba6a3;
  373. font-family: 'Source Han Sans CN VF';
  374. font-size: 28rpx;
  375. font-weight: 400;
  376. .automation-footer-left-num {
  377. color: #14a478;
  378. text-align: center;
  379. font-family: 'Source Han Sans CN VF';
  380. font-size: 28rpx;
  381. font-style: normal;
  382. font-weight: 700;
  383. margin: 0 8rpx;
  384. }
  385. }
  386. .automation-footer-right {
  387. width: 224rpx;
  388. border-radius: 16rpx;
  389. background-color: #14a478;
  390. color: #ffffff;
  391. text-align: center;
  392. font-family: 'Source Han Sans CN VF';
  393. font-size: 32rpx;
  394. font-weight: 400;
  395. padding: 16rpx 0;
  396. margin-right: 32rpx;
  397. }
  398. }
  399. }
  400. </style>