offerPopup.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <template>
  2. <popup class="offer-popup" teleport="body" :overlay-style="{'z-index': 9999}" v-model:show="show" :close-on-click-overlay="false" :closeable="stepIndex === 2">
  3. <div class="step-1" v-if="stepIndex === 1">
  4. <div class="title">
  5. <div class="text">
  6. <div>请输入</div>
  7. <div class="blue">实际交易金额</div>
  8. </div>
  9. <img src="@/assets/img/home/offer-icon.png" alt="" />
  10. </div>
  11. <!-- <div class="tips">注:本次成本不对外公开,仅作为投入产出比的计算</div> -->
  12. <el-form ref="formRef" :model="formData" :rules="rules" label-width="0">
  13. <div class="inputs-wrap">
  14. <div class="input-row">
  15. <el-form-item prop="agriculturalInput" class="input-item">
  16. <div class="input-header">农资投入</div>
  17. <el-input
  18. class="input-field"
  19. type="number"
  20. v-model="formData.agriculturalInput"
  21. placeholder="请输入数字"
  22. >
  23. <template #suffix>
  24. <span class="unit">元</span>
  25. </template>
  26. </el-input>
  27. </el-form-item>
  28. <el-form-item prop="serviceInput" class="input-item">
  29. <div class="input-header">农服投入</div>
  30. <el-input
  31. class="input-field"
  32. type="number"
  33. v-model="formData.serviceInput"
  34. placeholder="请输入数字"
  35. >
  36. <template #suffix>
  37. <span class="unit">元</span>
  38. </template>
  39. </el-input>
  40. </el-form-item>
  41. </div>
  42. <div class="input-row total-row">
  43. <div class="total-label">总金额</div>
  44. <el-form-item prop="totalAmount" class="total-form-item">
  45. <el-input
  46. class="input-field total-input"
  47. type="number"
  48. v-model="formData.totalAmount"
  49. placeholder="请输入数字"
  50. >
  51. <template #suffix>
  52. <span class="unit">元</span>
  53. </template>
  54. </el-input>
  55. </el-form-item>
  56. </div>
  57. </div>
  58. </el-form>
  59. </div>
  60. <div class="step-2" v-else>
  61. <div class="upload-wrap" :class="{ 'upload-cont': fileList.length }">
  62. <div class="name"><span class="required">*</span>请上传执行照片(至少两张)</div>
  63. <uploader
  64. class="uploader"
  65. v-model="fileList"
  66. multiple
  67. :max-count="5"
  68. :after-read="afterRead"
  69. @click="handleClick('rg')"
  70. >
  71. <img class="img" v-show="!fileList.length" src="@/assets/img/home/example-4.png" alt="" />
  72. <img class="plus" src="@/assets/img/home/plus.png" alt="" />
  73. </uploader>
  74. </div>
  75. <div class="time-wrap">
  76. <div class="name"><span class="required">*</span>请选择 {{ executionData.farmWorkName }} 实际执行时间</div>
  77. <div class="time-input">
  78. <el-date-picker
  79. v-model="executeTime"
  80. popper-style="z-index: 99999 !important;"
  81. :disabled-date="disabledDate"
  82. size="large"
  83. style="width: 100%"
  84. type="date"
  85. placeholder="请选择日期"
  86. :editable="false"
  87. />
  88. </div>
  89. </div>
  90. </div>
  91. <div class="tips-text">注:交易信息保密不公开</div>
  92. <div class="button-wrap" v-if="stepIndex === 1">
  93. <div class="button second" @click="handleCancel">取消</div>
  94. <div
  95. @click="handleNextStep"
  96. class="button primary"
  97. :class="{ 'btn-color': formData.totalAmount && formData.totalAmount.length > 0 }"
  98. >
  99. 下一步
  100. </div>
  101. </div>
  102. <div class="button-wrap" v-if="stepIndex === 2">
  103. <div class="button second" @click="toggleStep(1)">上一步</div>
  104. <div v-if="stepIndex === 2" @click="closeTask" class="button primary btn-color">确认上传</div>
  105. </div>
  106. </popup>
  107. </template>
  108. <script setup>
  109. import { Popup, Uploader } from "vant";
  110. import { ref, watch, reactive } from "vue";
  111. import { useStore } from "vuex";
  112. import { getFileExt } from "@/utils/util";
  113. import UploadFile from "@/utils/upliadFile";
  114. import { base_img_url2 } from "@/api/config";
  115. import { ElMessage, ElMessageBox } from "element-plus";
  116. import wx from "weixin-js-sdk";
  117. import { useRouter } from "vue-router";
  118. const router = useRouter();
  119. const store = useStore();
  120. const miniUserId = store.state.home.miniUserId;
  121. const show = ref(false);
  122. const formRef = ref(null);
  123. const formData = reactive({
  124. agriculturalInput: "",
  125. serviceInput: "",
  126. totalAmount: "",
  127. });
  128. const rules = {
  129. agriculturalInput: [
  130. { required: false, message: "请输入农资投入", trigger: "blur" },
  131. {
  132. validator: (rule, value, callback) => {
  133. if (isNaN(value) || Number(value) < 0) {
  134. callback(new Error("请输入有效的数字"));
  135. } else {
  136. callback();
  137. }
  138. },
  139. trigger: "blur",
  140. },
  141. ],
  142. serviceInput: [
  143. { required: false, message: "请输入农服投入", trigger: "blur" },
  144. {
  145. validator: (rule, value, callback) => {
  146. if (isNaN(value) || Number(value) < 0) {
  147. callback(new Error("请输入有效的数字"));
  148. } else {
  149. callback();
  150. }
  151. },
  152. trigger: "blur",
  153. },
  154. ],
  155. totalAmount: [
  156. { required: true, message: "请输入总金额", trigger: "blur" },
  157. {
  158. validator: (rule, value, callback) => {
  159. if (!value || value.trim() === "") {
  160. callback(new Error("请输入总金额"));
  161. } else if (isNaN(value) || Number(value) < 0) {
  162. callback(new Error("请输入有效的数字"));
  163. } else {
  164. callback();
  165. }
  166. },
  167. trigger: "blur",
  168. },
  169. ],
  170. };
  171. const stepIndex = ref(1);
  172. const executeTime = ref("");
  173. const fileList = ref([]);
  174. const fileArr = ref([]);
  175. const imgType = ref("");
  176. const handleClick = (type) => {
  177. imgType.value = type;
  178. };
  179. const handleCancel = () => {
  180. show.value = false;
  181. resetForm();
  182. };
  183. const uploadFileObj = new UploadFile();
  184. const afterRead = (file) => {
  185. // 处理多张照片的情况:file 可能是数组
  186. const files = Array.isArray(file) ? file : [file];
  187. files.forEach((item) => {
  188. // 将文件上传至服务器
  189. let fileVal = item.file;
  190. if (!fileVal) return; // 如果没有 file 属性,跳过
  191. item.status = "uploading";
  192. item.message = "上传中...";
  193. let ext = getFileExt(fileVal.name);
  194. let key = `birdseye-look-mini/${miniUserId}/${new Date().getTime()}.${ext}`;
  195. uploadFileObj.put(key, fileVal).then((resFilename) => {
  196. item.status = "done";
  197. item.message = "";
  198. fileArr.value.push(resFilename);
  199. }).catch(() => {
  200. item.status = 'failed';
  201. item.message = '上传失败';
  202. ElMessage.error('图片上传失败,请稍后再试!')
  203. });
  204. });
  205. };
  206. function toggleStep(val) {
  207. stepIndex.value = val;
  208. }
  209. function resetForm() {
  210. // 重置表单验证状态
  211. if (formRef.value) {
  212. formRef.value.clearValidate();
  213. formRef.value.resetFields();
  214. }
  215. }
  216. function handleNextStep() {
  217. if (!formRef.value) return;
  218. formRef.value.validate((valid) => {
  219. if (valid) {
  220. toggleStep(2);
  221. } else {
  222. ElMessage.warning("请完善信息");
  223. }
  224. });
  225. }
  226. function formatDate(date) {
  227. let year = date.getFullYear();
  228. let month = String(date.getMonth() + 1).padStart(2, "0");
  229. let day = String(date.getDate()).padStart(2, "0");
  230. return `${year}-${month}-${day}`;
  231. }
  232. const emit = defineEmits(['uploadSuccess']);
  233. function closeTask() {
  234. // stepIndex.value = 2
  235. if (!fileArr.value.length || fileArr.value.length < 2) return ElMessage.warning('请上传至少两张图片')
  236. if (!executeTime.value) return ElMessage.warning('请选择实际执行时间')
  237. const params = {
  238. recordId: executionData.value.id,
  239. executeDate: formatDate(executeTime.value),
  240. executeEvidence: fileArr.value,
  241. actualAgriculturalInput: formData.agriculturalInput,
  242. actualFarmServiceInput: formData.serviceInput,
  243. actualTotalInput: formData.totalAmount,
  244. }
  245. VE_API.z_farm_work_record.addExecuteImgAndComplete(params).then((res) => {
  246. if (res.code === 0) {
  247. ElMessage.success('上传成功')
  248. show.value = false
  249. emit('uploadSuccess')
  250. }
  251. })
  252. // show.value = false;
  253. // router.push("/review_work");
  254. // if(!input.value.length) return ElMessage.warning('请上传图片')
  255. // const params = {
  256. // ...props.executionData,
  257. // orderStatus: 4,
  258. // farmWorkservicecost: input.value,
  259. // confirmPicture: fileArr.value
  260. // }
  261. // VE_API.order.confirm(params).then(({ code }) => {
  262. // if (code === 0) {
  263. // ElMessage({
  264. // message: "操作成功",
  265. // type: "success",
  266. // });
  267. // setTimeout(() => {
  268. // // wx.miniProgram.navigateBack()
  269. // router.replace("/feature_home_album?list=true");
  270. // }, 500)
  271. // }
  272. // })
  273. }
  274. // 计算总金额
  275. function calculateTotalAmount() {
  276. const agricultural = parseFloat(formData.agriculturalInput) || 0;
  277. const service = parseFloat(formData.serviceInput) || 0;
  278. if (agricultural > 0 || service > 0) {
  279. const total = agricultural + service;
  280. formData.totalAmount = total > 0 ? total.toString() : "";
  281. formRef.value.validateField("totalAmount");
  282. } else {
  283. formData.totalAmount = "";
  284. }
  285. }
  286. // 监听农资投入和农服投入的变化,自动计算总金额
  287. watch(
  288. () => [formData.agriculturalInput, formData.serviceInput],
  289. () => {
  290. calculateTotalAmount();
  291. }
  292. );
  293. const executionData = ref(null);
  294. function openPopup(item) {
  295. show.value = true;
  296. executionData.value = item;
  297. stepIndex.value = 1;
  298. fileArr.value = [];
  299. fileList.value = [];
  300. // 重置表单数据
  301. formData.agriculturalInput = "";
  302. formData.serviceInput = "";
  303. formData.totalAmount = "";
  304. }
  305. const disabledDate = (time) => {
  306. // 获取今天的开始时间(00:00:00)
  307. const today = new Date();
  308. today.setHours(0, 0, 0, 0);
  309. // 获取明天的开始时间(00:00:00)
  310. const tomorrow = new Date(today);
  311. tomorrow.setDate(tomorrow.getDate() + 1);
  312. // 如果时间 >= 明天的开始时间,则禁用(不能选今天之后)
  313. // 可以选择今天及之前的时间
  314. return time.getTime() >= tomorrow.getTime();
  315. }
  316. defineExpose({
  317. openPopup,
  318. });
  319. </script>
  320. <style lang="scss" scoped>
  321. .offer-popup {
  322. z-index: 9999 !important;
  323. width: 90%;
  324. padding: 10px 12px;
  325. border-radius: 8px;
  326. background: linear-gradient(360deg, #ffffff 74.2%, #d1ebff 100%);
  327. ::v-deep {
  328. .van-popup__close-icon {
  329. color: #000;
  330. }
  331. }
  332. .step-1 {
  333. .tips {
  334. color: #2199f8;
  335. padding: 4px;
  336. font-family: "PangMenZhengDao";
  337. background: rgba(33, 153, 248, 0.1);
  338. border-radius: 4px;
  339. text-align: center;
  340. margin-bottom: 8px;
  341. }
  342. }
  343. .title {
  344. margin: 10px 0 12px 0;
  345. display: flex;
  346. align-items: stretch;
  347. justify-content: space-between;
  348. .text {
  349. font-size: 30px;
  350. div {
  351. font-family: "PangMenZhengDao";
  352. line-height: 38px;
  353. }
  354. .blue {
  355. color: #2199f8;
  356. margin-top: -5px;
  357. }
  358. }
  359. img {
  360. width: 96px;
  361. height: 96px;
  362. }
  363. }
  364. .input {
  365. width: 100%;
  366. ::v-deep {
  367. .el-input__inner {
  368. text-align: center;
  369. }
  370. --el-input-placeholder-color: rgba(33, 153, 248, 0.43);
  371. }
  372. }
  373. .inputs-wrap {
  374. ::v-deep {
  375. .el-form-item {
  376. margin-bottom: 0;
  377. .el-form-item__error {
  378. position: absolute;
  379. bottom: -18px;
  380. left: 0;
  381. font-size: 12px;
  382. color: #f56c6c;
  383. line-height: 1;
  384. padding-top: 2px;
  385. }
  386. }
  387. .el-input__wrapper {
  388. border-radius: 6px;
  389. border: 1px solid rgba(162, 213, 253, 0.8);
  390. box-shadow: none;
  391. padding: 7px 12px;
  392. background: #fff;
  393. &.is-error {
  394. border-color: #f56c6c;
  395. }
  396. }
  397. .el-input__inner {
  398. text-align: left;
  399. color: #000000;
  400. font-size: 16px;
  401. }
  402. .el-input__suffix {
  403. .unit {
  404. color: rgba(0, 0, 0, 0.2);
  405. font-size: 16px;
  406. }
  407. }
  408. }
  409. .input-row {
  410. display: flex;
  411. gap: 12px;
  412. margin-bottom: 20px;
  413. position: relative;
  414. .input-item {
  415. flex: 1;
  416. position: relative;
  417. .input-header {
  418. background: #2199f8;
  419. color: #fff;
  420. padding: 0 12px;
  421. border-radius: 6px 6px 0 0;
  422. font-size: 16px;
  423. text-align: center;
  424. line-height: 28px;
  425. width: 100%;
  426. }
  427. .input-field {
  428. ::v-deep {
  429. .el-input__wrapper {
  430. border-radius: 0 0 6px 6px;
  431. border-top: none;
  432. }
  433. }
  434. }
  435. }
  436. &.total-row {
  437. align-items: center;
  438. margin-bottom: 0;
  439. .total-label {
  440. color: #2199f8;
  441. font-size: 16px;
  442. min-width: 60px;
  443. }
  444. .total-form-item {
  445. flex: 1;
  446. position: relative;
  447. }
  448. .total-input {
  449. flex: 1;
  450. }
  451. }
  452. }
  453. }
  454. .tips-text {
  455. font-size: 14px;
  456. color: #b0b0b0;
  457. text-align: center;
  458. margin-top: 16px;
  459. }
  460. .button-wrap {
  461. display: flex;
  462. padding: 16px 0 10px 0;
  463. }
  464. .button {
  465. border-radius: 20px;
  466. color: #fff;
  467. padding: 7px 0;
  468. text-align: center;
  469. font-size: 16px;
  470. &.primary {
  471. margin-left: 12px;
  472. flex: 1;
  473. background: #2199f8;
  474. color: #fff;
  475. &.btn-color {
  476. background: #2199f8;
  477. }
  478. }
  479. &.second {
  480. color: #666666;
  481. text-align: center;
  482. font-size: 16px;
  483. width: 100px;
  484. border: 1px solid #bbbbbb;
  485. }
  486. }
  487. }
  488. .upload-wrap {
  489. ::v-deep {
  490. .avatar-uploader .el-upload {
  491. width: 100%;
  492. border: 1px dashed #dddddd;
  493. border-radius: 6px;
  494. cursor: pointer;
  495. position: relative;
  496. overflow: hidden;
  497. }
  498. .van-uploader,
  499. .van-uploader__wrapper,
  500. .van-uploader__input-wrapper {
  501. width: 100%;
  502. }
  503. .el-icon.avatar-uploader-icon {
  504. font-size: 28px;
  505. color: #8c939d;
  506. width: 100%;
  507. height: 128px;
  508. text-align: center;
  509. background: #f6f6f6;
  510. }
  511. }
  512. }
  513. .step-2 {
  514. .title {
  515. margin: 0;
  516. .text {
  517. margin: 0 auto;
  518. }
  519. text-align: center;
  520. }
  521. .tips {
  522. font-family: "PangMenZhengDao";
  523. color: #9a9a9a;
  524. font-size: 14px;
  525. background: linear-gradient(0deg, #ffffff 55%, rgba(33, 153, 248, 0.25) 100%);
  526. border: 1px solid rgba(33, 153, 248, 0.4);
  527. border-radius: 25px;
  528. width: 80%;
  529. margin: 5px auto 20px auto;
  530. text-align: center;
  531. span {
  532. color: #269fff;
  533. }
  534. }
  535. .name {
  536. color: #000000;
  537. font-size: 16px;
  538. font-weight: 500;
  539. padding-bottom: 12px;
  540. .required {
  541. color: #ff4d4f;
  542. margin-right: 2px;
  543. }
  544. }
  545. .upload-wrap {
  546. // position: relative;
  547. // border: 1px dashed #2199F8;
  548. // background: rgba(33, 153, 248, 0.1);
  549. border-radius: 10px;
  550. padding: 14px 0 10px 0;
  551. &.upload-cont {
  552. ::v-deep {
  553. .van-uploader__wrapper {
  554. flex-wrap: nowrap;
  555. }
  556. }
  557. }
  558. .img {
  559. width: 80px;
  560. height: 80px;
  561. margin-right: 12px;
  562. }
  563. .plus {
  564. margin-right: 12px;
  565. width: 80px;
  566. height: 80px;
  567. }
  568. }
  569. .upload-wrap + .upload-wrap {
  570. margin-top: 12px;
  571. }
  572. }
  573. </style>