productlist.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <template>
  2. <el-row :gutter="10">
  3. <el-col :span="setcol">
  4. <div class="flex-align-center normal-margin">
  5. <slot name="operation"></slot>
  6. <!-- <el-button v-if="data.status === '新建'" class="inline-16" :disabled="data.type === '特殊订单'" size="small" type="primary" @click="drawer = true">{{setcol === 24?'添 加':'取 消'}}</el-button>-->
  7. <addProduct
  8. class="inline-16"
  9. v-if="
  10. type !== 'confirmdate' &&
  11. data.status === '新建' &&
  12. data.type !== '特殊订单'
  13. "
  14. :drawer="drawer"
  15. :data="data"
  16. ref="addProduct"
  17. :params="paramsAdd"
  18. :tablecolsAdd="tablecolsAdd"
  19. :title="$t(`添 加`)"
  20. :tradefield="data.tradefield"
  21. :querySa_brandid="data.sa_brandid"
  22. @addSuccess="addProducts"
  23. @addProduct="addProduct"
  24. @uploadData="uploadData"
  25. @closeDrawer="
  26. listData();
  27. $emit('onSuccess');
  28. "
  29. ></addProduct>
  30. <!-- <excel class="inline-16" :tablecols="columnTitle" :param="param" :total="total" :excelTitle="excelTitle"></excel>-->
  31. <uploadAllData
  32. v-if="
  33. type !== 'confirmdate' &&
  34. data.status === '新建' &&
  35. data.type !== '特殊订单'
  36. "
  37. :total="total"
  38. @onSuccess="
  39. listData();
  40. $emit('onSuccess');
  41. "
  42. @handlePullApi="handlePullApi"
  43. @handleDelApi="handleDelApi"
  44. idName="sa_orderitemsid"
  45. type="del"
  46. ></uploadAllData>
  47. </div>
  48. <p
  49. v-if="data.status === '新建'"
  50. class="normal-margin"
  51. style="font-size: 13px !important; color: red; font-weight: normal"
  52. >
  53. {{ $t(checkFreefreightamount) }}
  54. </p>
  55. <Table
  56. height="calc(100vh - 500px)"
  57. ref="multipleTable"
  58. :layout="tablecols"
  59. :data="tableData"
  60. :custom="true"
  61. :checkbox="true"
  62. fixedName="rowno itemname itemno erpitemno model"
  63. redirect="left"
  64. :headerOptions="['needdate']"
  65. @selectionChange="selectionChange"
  66. >
  67. <template v-slot:header="scope">
  68. <div v-if="scope.column.columnname == 'needdate'">
  69. <el-date-picker
  70. style="width: 180px"
  71. v-if="data.status === '新建'"
  72. v-model="value2"
  73. value-format="yyyy-MM-dd"
  74. slot="reference"
  75. align="right"
  76. type="date"
  77. size="mini"
  78. :placeholder="$t(`一键交期`)"
  79. :picker-options="pickerOptions"
  80. @change="dateChange(scope.column.data)"
  81. >
  82. </el-date-picker>
  83. <span v-else>{{$t('需求日期')}}</span>
  84. </div>
  85. </template>
  86. <template v-slot:customcol="scope">
  87. <div v-if="scope.column.columnname === 'qty'">
  88. <el-input-number
  89. :controls="true"
  90. controls-position="right"
  91. :step-strictly="true"
  92. v-if="data.status === '新建' && data.type != '特殊订单'"
  93. size="mini"
  94. v-model="scope.column.data.qty"
  95. :min="scope.column.data.orderminqty"
  96. :step="scope.column.data.orderaddqty"
  97. :label="$t(`输入数量`)"
  98. @change="qtyChange(scope.column.data, scope.$index)"
  99. ></el-input-number>
  100. <span v-else>{{ scope.column.data.qty }}</span>
  101. </div>
  102. <div v-else-if="scope.column.columnname === 'needdate'">
  103. <el-date-picker
  104. v-if="scope.column.data.delivery > 0 && data.status === '新建'"
  105. v-model="scope.column.data.needdate"
  106. type="date"
  107. :placeholder="$t('选择日期')"
  108. value-format="yyyy-MM-dd"
  109. size="mini"
  110. style="width: 150px"
  111. :picker-options="pickerOptions"
  112. @change="onDateChange(scope.column.data)"
  113. @focus="setPickerOptions(scope.column.data)"
  114. >
  115. </el-date-picker>
  116. <div v-else>
  117. <p v-if="scope.column.data.delivery === 0">{{$t('不管控交期')}}</p>
  118. <p v-else>{{ scope.column.data.needdate }}</p>
  119. </div>
  120. </div>
  121. <div v-else-if="scope.column.columnname === 'unit'">
  122. <el-tag size="mini" type="info" effect="plain">{{
  123. scope.column.data.unit
  124. }}</el-tag>
  125. </div>
  126. <div v-else-if="scope.column.columnname === 'marketprice'">
  127. <p>
  128. ¥&nbsp;{{ tool.formatAmount(scope.column.data.marketprice, 2) }}
  129. </p>
  130. </div>
  131. <div v-else-if="scope.column.columnname === 'defaultprice'">
  132. <p>
  133. ¥&nbsp;{{ tool.formatAmount(scope.column.data.defaultprice, 2) }}
  134. </p>
  135. </div>
  136. <div v-else-if="scope.column.columnname === 'defaultamount'">
  137. <p style="color: red; font-weight: 500">
  138. ¥&nbsp;{{
  139. tool.formatAmount(
  140. scope.column.data.defaultprice * scope.column.data.qty,
  141. 2
  142. )
  143. }}
  144. </p>
  145. </div>
  146. <div v-else-if="scope.column.columnname === 'price'">
  147. <p>¥&nbsp;{{ tool.formatAmount(scope.column.data.price, 2) }}</p>
  148. </div>
  149. <div v-else-if="scope.column.columnname === 'amount'">
  150. <p style="color: red; font-weight: 500">
  151. ¥&nbsp;{{ tool.formatAmount(scope.column.data.amount, 2) }}
  152. </p>
  153. </div>
  154. <div v-else-if="scope.column.columnname === 'aftersalesmagamount'">
  155. <p style="color: red; font-weight: 500">
  156. ¥&nbsp;{{ tool.formatAmount(scope.column.data.aftersalesmagamount, 2) }}
  157. </p>
  158. </div>
  159. <div v-else-if="scope.column.columnname === 'remarks'">
  160. <el-input
  161. v-model="scope.column.data.remarks"
  162. :placeholder="$t(`输入订单备注`)"
  163. size="mini"
  164. @blur="onConfirm([scope.column.data], true, true)"
  165. ></el-input>
  166. </div>
  167. <div v-else-if="scope.column.columnname == 'cansaleqty' || scope.column.columnname == 'undeliqty' || scope.column.columnname == 'aftersalesmagqty'">
  168. {{scope.column.data[scope.column.columnname]?scope.column.data[scope.column.columnname]:'0'}}
  169. </div>
  170. <div v-else-if="scope.column.columnname == 'invoiceamount' || scope.column.columnname == 'writeoffamount' || scope.column.columnname == 'aftersalesmagamount'">
  171. {{scope.column.data[scope.column.columnname]?tool.formatAmount(scope.column.data[scope.column.columnname],2,'¥'):'¥0.00'}}
  172. </div>
  173. <div v-else-if="scope.column.columnname == 'operation'"></div>
  174. <p v-else>{{ $t(scope.column.data[scope.column.columnname]) || '--'}}</p>
  175. </template>
  176. <template v-slot:opreation="scope">
  177. <!-- <el-button v-if="data.status == '新建' && data.type != '特殊订单'" type="text" size="mini" @click="deleteOrderProduct(scope.data)">{{$t('删 除')}}</el-button> -->
  178. <el-button
  179. v-if="data.status == '新建'"
  180. type="text"
  181. size="mini"
  182. @click="deleteOrderProduct(scope.data)"
  183. >{{ $t("删 除") }}</el-button
  184. >
  185. </template>
  186. </Table>
  187. <div style="margin-top: 16px; text-align: right">
  188. <el-pagination
  189. background
  190. small
  191. @size-change="handleSizeChange"
  192. @current-change="handleCurrentChange"
  193. :current-page="currentPage"
  194. :page-size="param.content.pageSize"
  195. layout="total, prev, pager, next, jumper"
  196. :total="total"
  197. >
  198. </el-pagination>
  199. </div>
  200. </el-col>
  201. <el-col :span="24 - setcol">
  202. <el-drawer
  203. :title="$t(`添加商品`)"
  204. :visible.sync="drawer"
  205. append-to-body
  206. direction="rtl"
  207. size="80%"
  208. >
  209. <div class="drawer__panel">
  210. <addProduct
  211. :drawer="drawer"
  212. :data="data"
  213. @onConfirm="onConfirm"
  214. ></addProduct>
  215. </div>
  216. </el-drawer>
  217. </el-col>
  218. </el-row>
  219. </template>
  220. <script>
  221. // import addProduct from '@/template/orderCanUseProduct/index.vue'
  222. import addProduct from "@/template/addProduct/index1";
  223. import uploadAllData from "@/components/uploadAllData/index";
  224. import Table from "@/HDrpManagement/orderManage/details/tabs/table";
  225. export default {
  226. props: ["data", "type"],
  227. data() {
  228. return {
  229. flag: 0,
  230. freefreightamount: null,
  231. drawer: false,
  232. setcol: 24,
  233. dataRefresh: true,
  234. tableData: [],
  235. tablecols: [],
  236. columnTitle: [],
  237. excelTitle: "订单明细",
  238. param: {
  239. id: 20221109093902,
  240. content: {
  241. sa_orderid: this.$route.query.id, //订单ID
  242. pageNumber: 1,
  243. pageSize: 10000,
  244. where: {
  245. condition: "",
  246. },
  247. },
  248. },
  249. pickerOptions: {
  250. disabledDate(time) {
  251. return time.getTime() < Date.now() - 24 * 3600 * 1000;
  252. },
  253. },
  254. total: 0,
  255. currentPage: 0,
  256. time: null,
  257. value2: "",
  258. paramsAdd: {
  259. id: null,
  260. content: {
  261. sa_orderid: this.$route.query.id, //订单ID
  262. pageNumber: 1,
  263. pageSize: 100,
  264. where: {
  265. condition: "",
  266. },
  267. },
  268. },
  269. tablecolsAdd: [],
  270. };
  271. },
  272. computed: {
  273. checkFreefreightamount() {
  274. let result = "";
  275. switch (this.freefreightamount) {
  276. case -1:
  277. result = this.$t("不免运费");
  278. break;
  279. case 0:
  280. result = this.$t("免运费");
  281. break;
  282. default:
  283. result =
  284. this.data.amount >= this.freefreightamount
  285. ? this.$t("当前订单免运费")
  286. : this.$t("订单满")+`‘${this.tool.formatAmount(
  287. this.freefreightamount,
  288. 2
  289. )}’${this.$t('元免运费,当前还差')}‘${this.tool.formatAmount(
  290. this.freefreightamount - this.data.amount,
  291. 2
  292. )}’${this.$t('元')}`;
  293. break;
  294. }
  295. return result;
  296. },
  297. },
  298. components: {
  299. /*excel:() => import('../export_excel'),*/
  300. excel: () => import("../details/export_excel"),
  301. addProduct,
  302. uploadAllData,
  303. Table,
  304. },
  305. methods: {
  306. async listData() {
  307. this.param.content.sa_orderid = this.$route.query.id;
  308. const res = await this.$api.requested(this.param);
  309. this.tableData = res.data;
  310. this.total = res.total;
  311. this.currentPage = res.pageNumber;
  312. setTimeout(() => {
  313. this.queryBasicInfo();
  314. }, 500);
  315. },
  316. handleSizeChange(val) {
  317. // console.log(`每页 ${val} 条`);
  318. this.params.content.pageSize = val;
  319. this.listData();
  320. },
  321. handleCurrentChange(val) {
  322. // console.log(`当前页: ${val}`);
  323. this.params.content.pageNumber = val;
  324. this.listData();
  325. },
  326. async deleteOrderProduct(row) {
  327. const res = await this.$api.requested({
  328. id: 20221109093702,
  329. content: {
  330. sa_orderid: this.$route.query.id,
  331. sa_orderitemsids: [row.sa_orderitemsid],
  332. },
  333. });
  334. this.tool.showMessage(res, () => {
  335. this.listData();
  336. this.$emit("onSuccess");
  337. });
  338. },
  339. // async updateOrderProduct (val) {
  340. // const res = await this.$api.requested({
  341. // "id": 20221110145302,
  342. // "content": val
  343. // })
  344. // this.$emit('onSuccess')
  345. // },
  346. qtyChange(val, index) {
  347. if (val.qty > val.orderminqty) {
  348. if ((val.qty - val.orderminqty) / val.orderaddqty > 0) {
  349. let k = ((val.qty - val.orderminqty) / val.orderaddqty).toFixed(0);
  350. val.qty = k * val.orderaddqty + val.orderminqty;
  351. }
  352. }
  353. let that = this;
  354. val.amount = val.qty * val.price;
  355. this.$set(this.tableData, index, val);
  356. // // 防抖
  357. if (this.time !== null) {
  358. clearTimeout(this.time);
  359. }
  360. this.time = setTimeout(() => {
  361. that.updateOrder({
  362. sa_orderid: this.data.sa_orderid, //订单ID
  363. sys_enterpriseid: this.data.sys_enterpriseid, //企业ID
  364. sa_contractid: this.data.contacts.contactsid, //合同ID
  365. type: this.data.type, //订单类型
  366. items: this.tableData,
  367. });
  368. this.$emit("qtyChange");
  369. }, 500);
  370. },
  371. onDateChange(val) {
  372. let that = this;
  373. that.value2 = "";
  374. that.updateOrder({
  375. sa_orderid: this.data.sa_orderid, //订单ID
  376. sys_enterpriseid: this.data.sys_enterpriseid, //企业ID
  377. sa_contractid: this.data.contacts.contactsid, //合同ID
  378. type: this.data.type, //订单类型
  379. items: this.tableData,
  380. });
  381. },
  382. async dateChange(row) {
  383. this.tableData = this.tableData.filter((e) => {
  384. if (e.delivery > 0) {
  385. e.needdate = this.value2;
  386. }
  387. return e;
  388. });
  389. const res = await this.$api.requested({
  390. id: 20230104143802,
  391. content: {
  392. sa_orderid: this.$route.query.id,
  393. needdate: this.value2,
  394. },
  395. });
  396. },
  397. async updateOrder(val) {
  398. const res = await this.$api.requested({
  399. id: 20221109093602,
  400. content: val,
  401. });
  402. this.time = null
  403. if (res.code == 1) {
  404. this.$emit("onSuccess");
  405. } else {
  406. this.$message({
  407. message: res.data + ":" + res.msg,
  408. type: "error",
  409. });
  410. this.listData();
  411. }
  412. },
  413. async setPickerOptions(val) {
  414. /*var startDate = val.deliverydate
  415. startDate = startDate.replace(new RegExp("-","gm"),"/")
  416. var startDateM = (new Date(startDate)).getTime()
  417. this.pickerOptions = {
  418. disabledDate(time) {
  419. return time.getTime() < startDateM;
  420. },
  421. }*/
  422. let newData = new Date();
  423. newData = newData.setDate(newData.getDate() + val.delivery + this.flag);
  424. let year = new Date(newData).getFullYear();
  425. let month = new Date(newData).getMonth() + 1;
  426. let day = new Date(newData).getDate();
  427. let param = {
  428. id: 20231008134404,
  429. content: {
  430. isExport: 0,
  431. isnext: "0",
  432. pageNumber: 1,
  433. pageSize: 100,
  434. where: {
  435. begindate: year + "-" + month + "-" + day,
  436. enddate: year + "-" + month + "-" + day,
  437. },
  438. },
  439. };
  440. const res = await this.$api.requested(param);
  441. if (res.data.length === 0) {
  442. this.flag = 0;
  443. newData = new Date(newData);
  444. newData = newData.setDate(newData.getDate() - 1);
  445. this.pickerOptions = {
  446. disabledDate(time) {
  447. return time.getTime() < newData;
  448. },
  449. };
  450. } else {
  451. this.flag = this.flag + 1;
  452. this.setPickerOptions(val);
  453. }
  454. },
  455. // 订单添加商品
  456. async onConfirm(data, edit, isupload) {
  457. if (isupload) {
  458. const res = await this.$api.requested({
  459. id: 20221109093602,
  460. content: {
  461. sa_orderid: this.$route.query.id, //订单ID
  462. sys_enterpriseid: this.data.sys_enterpriseid, //企业ID
  463. type: this.data.type, //订单类型
  464. items: data.map((e) => {
  465. return {
  466. sa_orderitemsid: edit ? e.sa_orderitemsid : 0,
  467. itemid: e.itemid,
  468. qty: e.qty,
  469. needdate: e.deliverydate,
  470. remarks: e.remarks,
  471. };
  472. }),
  473. },
  474. });
  475. }
  476. this.listData();
  477. this.$emit("onSuccess");
  478. },
  479. async queryBasicInfo() {
  480. const res = await this.$api.requested({
  481. id: 20220920084001,
  482. content: {
  483. sys_enterpriseid: this.data.sys_enterpriseid,
  484. },
  485. });
  486. this.freefreightamount = res.data.freefreightamount
  487. ? res.data.freefreightamount
  488. : 0;
  489. },
  490. /*批量添加商品*/
  491. async addProducts(data) {
  492. let items = data.map((item) => {
  493. return {
  494. sa_orderitemsid: 0,
  495. itemid: item.itemid,
  496. qty: item.orderminqty,
  497. needdate: item.deliverydate,
  498. };
  499. });
  500. const res = await this.$api.requested({
  501. id: 20221109093602,
  502. content: {
  503. sa_orderid: this.$route.query.id, //订单ID
  504. sys_enterpriseid: this.data.sys_enterpriseid, //企业ID
  505. type: this.data.type, //订单类型
  506. items: items,
  507. },
  508. });
  509. this.tool.showMessage(res, () => {
  510. this.listData();
  511. this.$refs.addProduct.listData();
  512. this.$emit("onSuccess");
  513. });
  514. },
  515. /*单个添加商品*/
  516. async addProduct(data) {
  517. let res = await this.$api.requested({
  518. id: 20221109093602,
  519. content: {
  520. sa_orderid: this.$route.query.id,
  521. sys_enterpriseid: this.data.sys_enterpriseid, //企业ID
  522. type: this.data.type, //订单类型
  523. items: [
  524. {
  525. sa_orderitemsid: 0,
  526. needdate: data.deliverydate,
  527. qty: data.orderminqty,
  528. itemid: data.itemid,
  529. },
  530. ],
  531. },
  532. });
  533. this.tool.showMessage(res, () => {
  534. this.listData();
  535. this.$refs.addProduct.listData();
  536. this.$emit("onSuccess");
  537. });
  538. },
  539. /*一键添加*/
  540. uploadData(uploadApi, data) {
  541. uploadApi.id = 20221109093602;
  542. uploadApi.content = {
  543. sa_orderid: this.$route.query.id,
  544. sys_enterpriseid: this.data.sys_enterpriseid, //企业ID
  545. type: this.data.type, //订单类型
  546. items: data.map((e) => {
  547. return {
  548. sa_orderitemsid: 0,
  549. needdate: e.deliverydate,
  550. qty: e.orderminqty,
  551. itemid: e.itemid,
  552. };
  553. }),
  554. };
  555. this.listData();
  556. this.$refs.addProduct.list = [];
  557. this.$emit("onSuccess");
  558. },
  559. handlePullApi(pullApi) {
  560. pullApi.content = {
  561. sa_orderid: 0, //订单ID
  562. pageNumber: 1,
  563. pageSize: 20,
  564. where: {
  565. condition: "",
  566. },
  567. };
  568. pullApi.id = 20221109093902;
  569. pullApi.content.sa_orderid = this.$route.query.id;
  570. },
  571. handleDelApi(delApi, data) {
  572. delApi.id = 20221109093702;
  573. delApi.content = {
  574. sa_orderid: this.$route.query.id,
  575. sa_orderitemsids: data,
  576. };
  577. this.$emit("onSuccess");
  578. },
  579. selectionChange (selection) {
  580. this.$emit('select',selection)
  581. },
  582. },
  583. mounted() {
  584. this.flag = 0;
  585. this.listData();
  586. console.log("表结构");
  587. // this.columnTitle = []
  588. // setTimeout(() => {
  589. // this.$refs.multipleTable.$refs.table.$children.forEach(obj => {
  590. // let columnChild = {'columnname':obj.prop,'filter':0,'rowindex':'','sequence':'','title':obj.label,'width':obj.width}
  591. // // 存到columnTitle数组中
  592. // this.columnTitle.push(columnChild)
  593. // })
  594. // },1000)
  595. },
  596. created() {
  597. this.tablecolsAdd = this.tool.tabelCol(
  598. this.$route.name
  599. ).addProductTable.tablecols;
  600. this.tablecols = this.tool.tabelCol(
  601. this.$route.name
  602. ).OrderListTable.tablecols;
  603. },
  604. watch: {
  605. value2(val) {
  606. console.log(val);
  607. },
  608. },
  609. };
  610. </script>
  611. <style scoped>
  612. /deep/ .el-input.is-disabled .el-input__inner {
  613. color: #666666;
  614. }
  615. /deep/.el-textarea.is-disabled .el-textarea__inner {
  616. color: #666666;
  617. }
  618. </style>