doSugar.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <!-- 远程做糖 -->
  3. <div class="sugarPage flex-col">
  4. <s-header :name="$t('device.remoteSugarMaking')" :noback="false"></s-header>
  5. <div class="box1 flex-col">
  6. <div class="block2 flex-row justify-between">
  7. <div class="block3 flex-col"></div>
  8. <span class="info2">{{ $t('device.equipmentName') }}:{{ deviceDetal ? deviceDetal.name : '' }}</span>
  9. </div>
  10. <div v-if="machineType === null || machineType === '0'">
  11. <van-field v-model="fieldValue" is-link readonly :label="$t('device.clickToSelectPattern')"
  12. :placeholder="$t('device.pleaseSelectAPattern')" @click="show = true" />
  13. <van-popup v-model:show="show" round position="bottom">
  14. <van-cascader v-model="cascaderValue" :title="$t('device.pleaseSelectAPattern')" :options="options"
  15. @close="show = false" @finish="onFinish">
  16. <template #option="{ option }">
  17. <div class="cascader-item">
  18. <van-image :src="option.imgUrl" width="55px" height="55px"></van-image>
  19. <div class="cascader-label">{{ option.value }}</div>
  20. </div>
  21. </template>
  22. </van-cascader>
  23. </van-popup>
  24. <div class="textRow o-pr-20">
  25. <span @click="pushToDaySugarList">{{ $t('device.todaysSugarList') }}>></span>
  26. </div>
  27. <div v-if="!doSugartData" class="block5 flex-col" @click="submitDoSugar"><span class="txt3">{{
  28. $t('device.submitToMakeSugar') }}</span></div>
  29. <van-button v-if="doSugartData" style="padding: 1em;" round type="primary" class="block5 flex-col"
  30. :disabled="doSugartType" @click="checkData()">{{ $t('device.viewResults') }}</van-button>
  31. </div>
  32. <div v-if="machineType === '1'">
  33. <van-field v-model="fieldValue" is-link readonly :label="$t('device.clickToSelectTaste')"
  34. :placeholder="$t('device.pleaseSelectTaste')" @click="show = true" />
  35. <van-popup v-model:show="show" round position="bottom">
  36. <van-cascader v-model="cascaderValue" :title="$t('device.pleaseSelectTaste')" :options="options"
  37. @close="show = false" @finish="onFinish">
  38. <template #option="{ option }">
  39. <div class="cascader-item">
  40. <van-image :src="option.imgUrl" width="55px" height="55px"></van-image>
  41. <div class="cascader-label">{{ option.value }}</div>
  42. </div>
  43. </template>
  44. </van-cascader>
  45. </van-popup>
  46. <div class="textRow o-pr-20">
  47. <span @click="pushToDaySugarList">{{ $t('device.todaysMakeList') }}>></span>
  48. </div>
  49. <div v-if="!doSugartData" class="block5 flex-col" @click="submitDoSugar"><span class="txt3">{{
  50. $t('device.submitToMakeSugar') }}</span></div>
  51. <van-button v-if="doSugartData" style="padding: 1em;" round type="primary" class="block5 flex-col"
  52. :disabled="doSugartType" @click="checkData()">{{ $t('device.viewResults') }}</van-button>
  53. </div>
  54. <div v-if="machineType === '2'">
  55. <van-collapse v-model="activeNames">
  56. <van-collapse-item :title="$t('device.jam')" name="1" size="large" title-style="color: #404d74;">
  57. <van-row class="goods">
  58. <van-col v-for="(item, index) in jamData" :key="index" class="goodsCon o-mlr-5 o-mb-20" span="11">
  59. <div class="l-flex-RC">
  60. <van-image width="50" height="50" fit="contain" :src="showPopPhoto(item)" />
  61. <span class="o-ml-10" style="color: #000;word-wrap: break-word; width: 50px;">{{ item.name }}</span>
  62. <van-checkbox class="o-ml-10" shape="square" v-model="item.checked" />
  63. </div>
  64. </van-col>
  65. </van-row>
  66. </van-collapse-item>
  67. <van-collapse-item :title="$t('device.nuts​')" name="2" size="large" title-style="color: #404d74;">
  68. <van-row class="goods">
  69. <van-col v-for="(item, index) in crushData" :key="index" class="goodsCon o-mlr-5 o-mb-20" span="11">
  70. <div class="l-flex-RC">
  71. <van-image width="50" height="50" fit="contain" :src="showPopPhoto(item)" />
  72. <span class="o-ml-10" style="color: #000;word-wrap: break-word; width: 50px;">{{ item.name }}</span>
  73. <van-checkbox class="o-ml-10" shape="square" v-model="item.checked" />
  74. </div>
  75. </van-col>
  76. </van-row>
  77. </van-collapse-item>
  78. </van-collapse>
  79. <br>
  80. <div class="textRow o-pr-20">
  81. <span @click="pushToDaySugarList">{{ $t('device.todaysMakeList') }}>></span>
  82. </div>
  83. <div v-if="!doSugartData" class="block5 flex-col" @click="submitDoSugar"><span class="txt3">{{
  84. $t('device.submitToMakeSugar') }}</span></div>
  85. <van-button v-if="doSugartData" style="padding: 1em;" round type="primary" class="block5 flex-col"
  86. :disabled="doSugartType" @click="checkData()">{{ $t('device.viewResults') }}</van-button>
  87. </div>
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import { onMounted, ref } from 'vue';
  93. import sHeader from "@/components/SimpleHeader";
  94. import { useRoute, useRouter } from 'vue-router';
  95. import {
  96. getDeviceDetal, selectProducts,
  97. doSugar,
  98. selectSugarStatus
  99. } from '@/service/device'
  100. import { showConfirmDialog, showFailToast, showSuccessToast, showToast } from 'vant';
  101. import { useI18n } from 'vue-i18n';
  102. import { styleUrl } from "../../common/js/utils";
  103. export default {
  104. setup() {
  105. const { t } = useI18n();
  106. const route = useRoute();
  107. const router = useRouter();
  108. const deviceId = route.query.deviceId;
  109. const machineType = route.query.machineType;
  110. const deviceDetal = ref(null);
  111. const show = ref(false);
  112. const fieldValue = ref('');
  113. const cascaderValue = ref('');
  114. const options = ref([]);
  115. const activeNames = ref(['1', '2']);
  116. // 果酱数据
  117. const iceName = ref();
  118. const jamData = ref([]);
  119. const crushData = ref([]);
  120. // 商品图片
  121. const showPopPhoto = (row) => {
  122. let imgId = row.no;
  123. if (imgId) {
  124. return require(`../../assets/order/spunSugar/goods/${imgId}.png`);
  125. }
  126. return imgId;
  127. };
  128. const onFinish = ({ selectedOptions }) => {
  129. console.log('onFinish', selectedOptions);
  130. show.value = false;
  131. fieldValue.value = selectedOptions[0].value
  132. }
  133. const doSugartData = ref(null);
  134. const doSugartType = ref(true);
  135. // 初始化页面获取列表
  136. onMounted(async () => {
  137. styleUrl('doSugar')
  138. getDeviceDetalFun();
  139. });
  140. const showSugarPhoto = (no) => {
  141. return require(`../../assets/order/spunSugar/goods/${no}.png`);
  142. };
  143. // 获取设备列表数据
  144. const getDeviceDetalFun = async () => {
  145. const { data } = await getDeviceDetal({ id: deviceId });
  146. if (data.code === '00000') {
  147. deviceDetal.value = data.data;
  148. getProduct();
  149. } else { showFailToast(data.message); }
  150. }
  151. // 获取花形下拉列表
  152. const getProduct = async () => {
  153. const { data } = await selectProducts({ equipmentId: deviceId });
  154. if (data.code) {
  155. if (machineType != '2') {
  156. options.value = data.data.map(item => {
  157. return {
  158. text: item.productName,
  159. value: item.productName,
  160. imgUrl: showSugarPhoto(item.no),
  161. };
  162. })
  163. } else {
  164. data.data.forEach(item => {
  165. if (item.no.includes('J01')) {
  166. // 果酱1
  167. jamData.value.push({
  168. name: item.productName,
  169. no: item.no,
  170. value: 1,
  171. checked: false
  172. });
  173. } else if (item.no.includes('J02')) {
  174. // 果酱2
  175. jamData.value.push({
  176. name: item.productName,
  177. no: item.no,
  178. value: 2,
  179. checked: false
  180. });
  181. } else if (item.no.includes('J03')) {
  182. // 果酱3
  183. jamData.value.push({
  184. name: item.productName,
  185. no: item.no,
  186. value: 3,
  187. checked: false
  188. });
  189. } else if (item.no.includes('C01')) {
  190. // 果碎1
  191. crushData.value.push({
  192. name: item.productName,
  193. no: item.no,
  194. value: 1,
  195. checked: false
  196. });
  197. } else if (item.no.includes('C02')) {
  198. // 果碎2
  199. crushData.value.push({
  200. name: item.productName,
  201. no: item.no,
  202. value: 2,
  203. checked: false
  204. });
  205. } else if (item.no.includes('I01')) {
  206. // 雪糕
  207. iceName.value = item.productName;
  208. }
  209. })
  210. }
  211. } else { showFailToast(data.message); }
  212. }
  213. const submitDoSugar = async () => {
  214. const makeCodes = ref([1, 0, 0]);
  215. doSugartData.value = null;
  216. doSugartType.value = true;
  217. if (machineType == '2') {
  218. fieldValue.value = '';
  219. let jamCount = 0;
  220. let crushCount = 0;
  221. // 如果是冰淇淋机器
  222. jamData.value.forEach(item => {
  223. if (item.checked) {
  224. fieldValue.value += item.name + ',';
  225. makeCodes.value[1] += item.value;
  226. jamCount++;
  227. }
  228. });
  229. crushData.value.forEach(item => {
  230. if (item.checked) {
  231. fieldValue.value += item.name + ',';
  232. makeCodes.value[2] += item.value;
  233. crushCount++;
  234. }
  235. });
  236. if (jamCount > 1) {
  237. makeCodes.value[1] += 1;
  238. }
  239. if (crushCount > 1) {
  240. makeCodes.value[2] += 1;
  241. }
  242. if (fieldValue.value === '') {
  243. fieldValue.value = iceName.value;
  244. } else {
  245. fieldValue.value = fieldValue.value.substring(0, fieldValue.value.length - 1);
  246. fieldValue.value = iceName.value + "(" + fieldValue.value + ")";
  247. }
  248. }
  249. if (fieldValue.value === '') { showFailToast(t('device.pleaseSelectAPattern')); return; }
  250. showConfirmDialog({
  251. title: t('user.tips'),
  252. message: t('device.confirmMake')+ fieldValue.value +'?',
  253. }).then(async() => {
  254. const { data } = await doSugar({ equipmentId: deviceId, productName: fieldValue.value, makeCodes: makeCodes.value.join(',') });
  255. if (data.code == "00000") {
  256. doSugartData.value = data.data;
  257. setTimeout(() => {
  258. doSugartType.value = false;
  259. }, 5000);
  260. } else { showFailToast(data.message); }
  261. }).catch((error) => {
  262. console.error(error);
  263. })
  264. }
  265. const checkData = async () => {
  266. const { data } = await selectSugarStatus({ no: doSugartData.value.no });
  267. if (data.code) {
  268. if (data.data == '1') {
  269. showToast(t('device.receiveInstruction'));
  270. } else {
  271. showSuccessToast(data.message);
  272. }
  273. doSugartData.value = null;
  274. doSugartType.value = true;
  275. } else {
  276. if (data.data == '0') {
  277. showToast(t('device.notUploadData'));
  278. } else if (data.data == '2') {
  279. showToast(t('device.machineException'));
  280. } else if (data.data == '3') {
  281. showToast(t('device.netException'));
  282. } else {
  283. showToast(data.message);
  284. }
  285. }
  286. };
  287. const pushToDaySugarList = async () => {
  288. router.push({ path: 'toDaySugarList', query: { deviceId: deviceId, clientId: deviceDetal.value.clientId } })
  289. }
  290. return {
  291. deviceDetal,
  292. show,
  293. fieldValue,
  294. cascaderValue,
  295. options,
  296. onFinish,
  297. submitDoSugar,
  298. doSugartData,
  299. doSugartType,
  300. checkData,
  301. pushToDaySugarList,
  302. showSugarPhoto,
  303. machineType,
  304. activeNames,
  305. jamData,
  306. crushData,
  307. showPopPhoto
  308. };
  309. },
  310. components: { sHeader },
  311. };
  312. </script>
  313. <style lang="less" scoped>
  314. @import "../../common/style/common";
  315. </style>