automation.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. this.getRunStatus().then((hasRunningTask) => {
  112. if (hasRunningTask) {
  113. setTimeout(() => {
  114. uni.redirectTo({
  115. url: `/pages/cb/shuifeizsFirst/rotationflow?devBid=${this.devBid}&devName=${this.devName}&devStatus=${this.devStatus}`,
  116. });
  117. }, 1000);
  118. } else {
  119. this.getdeviceSfStatus();
  120. this.getAlreadyList();
  121. }
  122. });
  123. },
  124. methods: {
  125. updateListHandler(list) {
  126. this.alreadyList = list;
  127. },
  128. updateFormData(options) {
  129. this.formData[options.key] = options.value;
  130. },
  131. async getAlreadyList() {
  132. const res = await this.$myRequest({
  133. url: '/api/v2/iot/mobile/device/sf/group/already/list/',
  134. method: 'post',
  135. data: {
  136. devBid: this.devBid,
  137. },
  138. });
  139. console.log(res, '-------------------- get already list');
  140. res?.forEach((item) => {
  141. item.isChecked = false;
  142. });
  143. this.alreadyList = res;
  144. },
  145. async getdeviceSfStatus() {
  146. const res = await this.$myRequest({
  147. url: '/api/v2/iot/mobile/device/sf/status/',
  148. method: 'post',
  149. data: {
  150. devBid: this.devBid,
  151. },
  152. });
  153. this.dataList = [];
  154. this.irrigatedAreaList = [];
  155. this.alreadyfertilizerBucketList = [];
  156. console.log('get device sf status', res);
  157. res.forEach((item) => {
  158. if (item.sfType === '7') {
  159. this.irrigatedAreaList.push(item);
  160. }
  161. });
  162. },
  163. clickHeaderItem(index) {
  164. this.activeIndex = index;
  165. this.tktype = index == 0 ? 1 : 2;
  166. },
  167. // 获取运行状态
  168. async getRunStatus() {
  169. try {
  170. const res = await this.$myRequest({
  171. url: '/api/v2/iot/mobile/device/sf/zsrf/task/run/status/',
  172. method: 'post',
  173. data: {
  174. devBid: this.devBid,
  175. },
  176. });
  177. console.log(res, 'resresresres');
  178. return Promise.resolve(res.status && res.status / 1 === 1);
  179. } catch (error) {
  180. return Promise.resolve(false);
  181. }
  182. },
  183. // iot/mobile/device/sf/zsrf/task/ctl/
  184. async postTaskCtl(payload) {
  185. // loading
  186. uni.showLoading({
  187. title: '正在执行',
  188. });
  189. console.log(payload, 'payloadpayload');
  190. const res = await this.$myRequest({
  191. url: '/api/v2/iot/mobile/device/sf/zsrf/task/ctl/',
  192. method: 'post',
  193. data: payload,
  194. header: {
  195. 'Content-Type': 'application/json',
  196. },
  197. });
  198. uni.hideLoading();
  199. console.log(res, 'resresres');
  200. if (res?.code === '000000') {
  201. uni.showToast({
  202. title: '操作成功',
  203. });
  204. setTimeout(() => {
  205. uni.redirectTo({
  206. url: `/pages/cb/shuifeizsFirst/rotationflow?devBid=${this.devBid}&devName=${this.devName}&devStatus=${this.devStatus}`,
  207. });
  208. }, 1000);
  209. } else {
  210. uni.showToast({
  211. icon: 'none',
  212. title: res.msg,
  213. });
  214. }
  215. },
  216. immediateExecution() {
  217. console.log(this.formData, 'formDataformDataformData');
  218. if (!this.formData['lgjg']) {
  219. uni.showToast({
  220. title: '请输入轮灌间隔时间',
  221. icon: 'none',
  222. });
  223. return;
  224. }
  225. if (this.tktype == 2 && !this.formData['fqcx']) {
  226. uni.showToast({
  227. title: '请输入肥前水时间',
  228. icon: 'none',
  229. });
  230. return;
  231. }
  232. if (this.tktype == 2 && !this.formData['fhcx']) {
  233. uni.showToast({
  234. title: '请输入肥后水时间',
  235. icon: 'none',
  236. });
  237. return;
  238. }
  239. if (this.tktype == 2 && !this.formData['sfmode']) {
  240. uni.showToast({
  241. title: '请选择模式',
  242. icon: 'none',
  243. });
  244. return;
  245. }
  246. if (this.selectNum === 0) {
  247. uni.showToast({
  248. title: '请选择灌区',
  249. icon: 'none',
  250. });
  251. return;
  252. }
  253. const fqList = [];
  254. for (let i = 0; i < this.alreadyList.length; i++) {
  255. const item = this.alreadyList[i];
  256. if (item.isChecked && !item.ti) {
  257. uni.showToast({
  258. title: `请输入${item.sfDisplayname || item.sfName}的时长`,
  259. icon: 'none',
  260. });
  261. return;
  262. } else if (item.isChecked && this.tktype == 2 && !item.pfCode) {
  263. uni.showToast({
  264. title: `请输入${item.sfDisplayname || item.sfName}的配方`,
  265. icon: 'none',
  266. });
  267. return;
  268. }
  269. if (item.isChecked) {
  270. fqList.push({
  271. fqCode: item.sfCode,
  272. ti: item.ti || '',
  273. pfCode: item.pfCode || '',
  274. });
  275. }
  276. }
  277. const payload = {
  278. devBid: this.devBid,
  279. tktype: this.tktype,
  280. tkid: 0,
  281. status: 1,
  282. ...this.formData,
  283. fqList,
  284. sfmode: this.tktype !== 1 ? this.formData.sfmode || 1 : '',
  285. };
  286. this.postTaskCtl(payload);
  287. },
  288. },
  289. };
  290. </script>
  291. <style scoped lang="scss">
  292. uni-page-body,
  293. uni-page-wrapper {
  294. position: relative;
  295. height: 100%;
  296. }
  297. .automation {
  298. background: linear-gradient(180deg, #ffffff00 0%, #fff 23.64%, #fff 100%),
  299. linear-gradient(102deg, #bfeadd 6.77%, #b8f1e7 40.15%, #b9eef5 84.02%);
  300. width: 100%;
  301. height: calc(100% - 100rpx);
  302. overflow: hidden;
  303. .automation-content {
  304. border-bottom: none;
  305. border-radius: 16rpx 16rpx 0 0;
  306. position: relative;
  307. overflow: hidden;
  308. &::before {
  309. position: absolute;
  310. content: '';
  311. top: 0;
  312. left: 0;
  313. right: 0;
  314. bottom: 0;
  315. background: url('https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/newindex/controlbg.png')
  316. no-repeat;
  317. background-size: cover;
  318. }
  319. }
  320. .automation-content-rever {
  321. border-bottom: none;
  322. border-radius: 16rpx 16rpx 0 0;
  323. position: relative;
  324. &::before {
  325. position: absolute;
  326. content: '';
  327. top: 0;
  328. left: 0;
  329. right: 0;
  330. bottom: 0;
  331. background: url('https://webstaticimg.oss-cn-hangzhou.aliyuncs.com/bigdata_app/newindex/controlbg.png')
  332. no-repeat;
  333. background-size: cover;
  334. transform: rotateY(180deg);
  335. transform-origin: center center;
  336. }
  337. }
  338. .automation-header {
  339. width: 100%;
  340. display: flex;
  341. .automation-header-item {
  342. width: 50%;
  343. height: 80rpx;
  344. display: flex;
  345. justify-content: center;
  346. align-items: center;
  347. font-size: 36rpx;
  348. color: #687a74;
  349. text-align: center;
  350. font-family: 'Source Han Sans CN VF';
  351. font-size: 32rpx;
  352. font-weight: 400;
  353. position: relative;
  354. }
  355. .automation-header-item-active {
  356. color: #042118;
  357. text-align: center;
  358. font-family: 'Source Han Sans CN VF';
  359. font-size: 32rpx;
  360. font-weight: 500;
  361. position: relative;
  362. }
  363. .automation-header-item-icon {
  364. width: 28rpx;
  365. height: 4rpx;
  366. border-radius: 4rpx;
  367. background-color: #14a478;
  368. position: absolute;
  369. bottom: 0;
  370. }
  371. .automation-header-item-icon-bottom {
  372. background-color: transparent;
  373. }
  374. }
  375. .automation-body {
  376. height: calc(100vh - 250rpx);
  377. overflow: hidden;
  378. .automation-body-title {
  379. position: relative;
  380. color: #042118;
  381. font-family: 'Source Han Sans CN VF';
  382. font-size: 28rpx;
  383. font-weight: 500;
  384. margin: 48rpx 32rpx 16rpx 32rpx;
  385. }
  386. }
  387. .automation-footer {
  388. position: fixed;
  389. width: 100%;
  390. padding: 16rpx 0;
  391. background: #fff;
  392. box-shadow: 0 -4rpx 8rpx 0 #0000001a;
  393. bottom: 0;
  394. height: 80rpx;
  395. display: flex;
  396. justify-content: space-between;
  397. align-items: center;
  398. .automation-footer-left {
  399. width: 50%;
  400. margin-left: 32rpx;
  401. color: #9ba6a3;
  402. font-family: 'Source Han Sans CN VF';
  403. font-size: 28rpx;
  404. font-weight: 400;
  405. .automation-footer-left-num {
  406. color: #14a478;
  407. text-align: center;
  408. font-family: 'Source Han Sans CN VF';
  409. font-size: 28rpx;
  410. font-style: normal;
  411. font-weight: 700;
  412. margin: 0 8rpx;
  413. }
  414. }
  415. .automation-footer-right {
  416. width: 224rpx;
  417. border-radius: 16rpx;
  418. background-color: #14a478;
  419. color: #ffffff;
  420. text-align: center;
  421. font-family: 'Source Han Sans CN VF';
  422. font-size: 32rpx;
  423. font-weight: 400;
  424. padding: 16rpx 0;
  425. margin-right: 32rpx;
  426. }
  427. }
  428. }
  429. </style>