supplychainon.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <view class="supplychainon-wrapper">
  3. <headerCom headerTitle="供应链列表" @headerJump="headerJump"></headerCom>
  4. <view class="headers-box">
  5. <searchVue
  6. placeholder="请输入商品名称"
  7. @search="onHandleSearch"
  8. ></searchVue>
  9. <tablist
  10. class="mt"
  11. :category="category"
  12. :curruntActive="curruntActive"
  13. @tabs="tabsHandleClick"
  14. ></tablist>
  15. </view>
  16. <view class="content-wrapper">
  17. <template v-if="list.length > 0">
  18. <ProductCard
  19. class="mrb"
  20. v-for="(item, index) in list"
  21. :key="index"
  22. :data="item"
  23. @status-change="handleStatusChange"
  24. @edit-price="handleEditPrice"
  25. @edit-activity="handleEditActivity"
  26. />
  27. </template>
  28. <template v-else>
  29. <emptyDataVue style="top: initial" />
  30. </template>
  31. <view
  32. v-if="tihsi == 0 && list.length > 0"
  33. class=""
  34. style="margin: 0rpx 0 30rpx 0; color: #999999; font-size: 26rpx"
  35. >
  36. —— 已经到最底部了哦 ——
  37. </view>
  38. </view>
  39. <priceEditModal
  40. v-if="isshow"
  41. :product-data="productObjData"
  42. :merInfo="merInfo"
  43. @close="priceEditModalClose"
  44. @confirm="confirm"
  45. />
  46. <!-- 弹窗主体 -->
  47. <uni-popup
  48. ref="popup"
  49. type="center"
  50. :is-mask-click="false"
  51. background-color="#rgba(0,0,0,0.5)"
  52. >
  53. <view class="popup-container" :class="[isOpen ? 'popup-show' : '']">
  54. <!-- 标题区 -->
  55. <view class="popup-header">
  56. <text class="title">活动设置</text>
  57. </view>
  58. <!-- 内容区 -->
  59. <view class="content-wrapper-popup">
  60. <view class="form-item">
  61. <uni-data-checkbox
  62. mode="button"
  63. icon="left"
  64. v-model="formData.radio"
  65. :localdata="rangeData"
  66. ></uni-data-checkbox>
  67. </view>
  68. <!-- 秒杀区块 -->
  69. <view class="form-item">
  70. <uni-data-checkbox
  71. mode="button"
  72. icon="left"
  73. v-model="formData.radios"
  74. :localdata="rangeData1"
  75. @change="onSwitchChange"
  76. ></uni-data-checkbox>
  77. </view>
  78. <!-- 价格输入 -->
  79. <view class="form-item">
  80. <view class="item-label">秒杀价格</view>
  81. <uni-easyinput
  82. v-model="formData.seckill_price"
  83. :errorMessage="isEmpty"
  84. focus
  85. placeholder="输入价格"
  86. :adjust-position="false"
  87. @change="changeInput"
  88. type="digit"
  89. ></uni-easyinput>
  90. </view>
  91. <!-- 时间选择 -->
  92. <view class="form-item">
  93. <view class="item-label">时间设置</view>
  94. <uni-datetime-picker
  95. type="datetime"
  96. v-model="formData.seckill_date"
  97. @change="onDateChange"
  98. />
  99. </view>
  100. </view>
  101. <!-- 操作按钮 -->
  102. <view class="action-btns">
  103. <button class="btn prev-step" @click="closePopup">取消</button>
  104. <button class="btn submit-btn" @click="handleSubmit">提交</button>
  105. </view>
  106. </view>
  107. </uni-popup>
  108. </view>
  109. </template>
  110. <script>
  111. import headerCom from "../../shop/components/headers/headers.vue";
  112. import searchVue from "./search/search.vue";
  113. import tablist from "./tablist.vue";
  114. import ProductCard from "./ProductCard.vue";
  115. import emptyDataVue from "../../shop/components/emptyData/emptyData.vue";
  116. import priceEditModal from "./price-edit-modal.vue";
  117. import {
  118. getSupplyChainList,
  119. getSupplyChainTab,
  120. postchangeshow,
  121. Addseckill, //活动
  122. } from "@/commit/product.js";
  123. import { getBaseInfo } from "@/commit/user.js";
  124. export default {
  125. components: {
  126. headerCom,
  127. searchVue,
  128. tablist,
  129. ProductCard,
  130. emptyDataVue,
  131. priceEditModal,
  132. },
  133. data() {
  134. return {
  135. page: 1,
  136. limit: 10,
  137. tihsi: "",
  138. list: [],
  139. keywords: "",
  140. is_panudn: true,
  141. productData: {},
  142. curruntActive: 0,
  143. category: [],
  144. type: 1,
  145. isshow: false,
  146. formData: {
  147. radio: "1",
  148. radios: "1",
  149. seckill_price: "",
  150. seckill_date: "",
  151. product_id: "",
  152. },
  153. isOpen: false,
  154. rangeData: [
  155. { value: "1", text: "大仓活动" },
  156. { value: "2", text: "平台活动" },
  157. ],
  158. rangeData1: [{ value: "1", text: "秒杀" }],
  159. isEmpty: false,
  160. dataObj: {},
  161. productObjData: {},
  162. merInfo: {},
  163. };
  164. },
  165. async onLoad(options) {
  166. this.curruntActive = options.indexs || options.tabIndex || "0";
  167. this.type = options.type || 1;
  168. await this.getSupplyChainTabData();
  169. await this.getSupplyChainListData();
  170. },
  171. onPullDownRefresh() {
  172. uni.showLoading({
  173. title: "加载中",
  174. });
  175. this.page = 1;
  176. this.is_panudn = true;
  177. this.list = [];
  178. this.getSupplyChainListData();
  179. },
  180. onReachBottom() {
  181. if (this.is_panudn == true) {
  182. this.page++;
  183. this.getSupplyChainListData();
  184. } else {
  185. return;
  186. }
  187. },
  188. methods: {
  189. getBaseInfoData() {
  190. getBaseInfo()
  191. .then((res) => {
  192. if (res.data.status === 200) {
  193. // console.log(res.data.data)
  194. this.merInfo = res.data.data || {};
  195. } else {
  196. this.merInfo = {};
  197. }
  198. })
  199. .catch((err) => {
  200. uni.showToast({
  201. title: res.data.message || "获取失败",
  202. mask: true,
  203. });
  204. });
  205. },
  206. async initData() {
  207. await this.getSupplyChainTabData();
  208. await this.getSupplyChainListData();
  209. },
  210. async tabsHandleClick({ index, item }) {
  211. this.indexs = index;
  212. this.curruntActive = index;
  213. this.list = [];
  214. this.type = item.type || 1;
  215. this.page = 1;
  216. this.is_panudn = true;
  217. uni.pageScrollTo({ scrollTop: 0, duration: 0 });
  218. await this.getSupplyChainListData();
  219. },
  220. async getSupplyChainTabData() {
  221. try {
  222. const res = await getSupplyChainTab();
  223. if (res.data.status === 200) {
  224. this.category = res.data.data || [];
  225. }
  226. } catch (error) {}
  227. },
  228. async getSupplyChainListData() {
  229. uni.showLoading({
  230. title: "加载中",
  231. });
  232. try {
  233. const res = await getSupplyChainList({
  234. page: this.page,
  235. limit: this.limit,
  236. keyword: this.keywords,
  237. type: this.type,
  238. spec_type: null, //商品规格 null 0 1
  239. });
  240. uni.stopPullDownRefresh();
  241. if (res.data.status === 200) {
  242. this.tihsi = res.data.data.list.length || 0;
  243. console.log(this.tihsi, "this.tihsi");
  244. if (res.data.data.count > 0) {
  245. if (this.page == 1) {
  246. this.list = res.data.data.list;
  247. } else {
  248. this.list = this.list.concat(res.data.data.list);
  249. }
  250. } else {
  251. if (this.page == 1) {
  252. this.list = [];
  253. }
  254. this.is_panudn = false;
  255. }
  256. uni.hideLoading();
  257. }
  258. } catch (error) {}
  259. },
  260. headerJump() {
  261. uni.switchTab({ url: "/shop/productManagementModule/index" });
  262. },
  263. async onHandleSearch(val) {
  264. this.keywords = val;
  265. await this.getSupplyChainListData();
  266. },
  267. handleStatusChange(row) {
  268. let ids = [];
  269. ids.push(row.product_id);
  270. uni.showLoading({
  271. title: "状态更改中",
  272. });
  273. postchangeshow({ ids: ids, is_show: row.is_show })
  274. .then((res) => {
  275. if (res.data.status === 200) {
  276. uni.showToast({
  277. title: res.data.message,
  278. icon: "none",
  279. });
  280. this.getSupplyChainTabData();
  281. this.getSupplyChainListData();
  282. }
  283. })
  284. .catch((err) => {
  285. uni.hideLoading();
  286. uni.hideToast();
  287. });
  288. },
  289. handleEditPrice(data) {
  290. this.productObjData = data;
  291. this.isshow = true;
  292. document.body.style.overflow = "hidden";
  293. this.getBaseInfoData();
  294. },
  295. priceEditModalClose() {
  296. this.isshow = false;
  297. document.body.style.overflow = "visible";
  298. },
  299. confirm() {
  300. this.isshow = false;
  301. this.initData();
  302. },
  303. handleEditActivity(data) {
  304. this.dataObj = data;
  305. this.isEmpty = false;
  306. this.showPopup();
  307. },
  308. showPopup() {
  309. this.isOpen = true;
  310. this.$refs.popup.open();
  311. },
  312. closePopup() {
  313. this.isOpen = false;
  314. this.formData.radio = "1";
  315. this.formData.radios = "1";
  316. this.formData.seckill_price = "";
  317. this.formData.seckill_date = "";
  318. this.$refs.popup.close();
  319. },
  320. onDateChange(data) {
  321. this.formData.seckill_date = data;
  322. },
  323. convertToISOString(dateStr) {
  324. // 将输入的日期时间字符串中的空格替换为 'T',以符合 ISO 8601 格式
  325. const isoFormatStr = dateStr.replace(" ", "T");
  326. // 创建 Date 对象
  327. const date = new Date(isoFormatStr);
  328. // 将 Date 对象转换为 ISO 8601 格式的字符串
  329. return date.toISOString();
  330. },
  331. async handleSubmit() {
  332. // 提交逻辑
  333. this.formData.product_id = this.dataObj.product_id;
  334. let params = JSON.parse(JSON.stringify(this.formData));
  335. if (
  336. params.seckill_price == "" ||
  337. params.seckill_price == null ||
  338. params.seckill_price == undefined
  339. ) {
  340. uni.showToast({
  341. title: "请输入秒杀价格",
  342. icon: "none",
  343. });
  344. this.isEmpty = true;
  345. return;
  346. }
  347. if (
  348. params.seckill_date == "" ||
  349. params.seckill_date == null ||
  350. params.seckill_date == undefined
  351. ) {
  352. uni.showToast({
  353. title: "请选择秒杀时间",
  354. icon: "none",
  355. });
  356. return;
  357. }
  358. params.seckill_date = this.convertToISOString(params.seckill_date);
  359. this.isEmpty = false;
  360. uni.showLoading({
  361. title: "秒杀活动添加中",
  362. });
  363. console.log(params);
  364. try {
  365. const res = await Addseckill(params);
  366. if (res.data.status == 200) {
  367. uni.showToast({
  368. title: "秒杀活动添加成功",
  369. icon: "none",
  370. });
  371. this.closePopup();
  372. this.initData();
  373. }
  374. } catch (error) {
  375. } finally {
  376. uni.hideLoading();
  377. uni.hideToast();
  378. }
  379. },
  380. changeInput(val) {
  381. if (val) {
  382. this.isEmpty = false;
  383. }
  384. },
  385. },
  386. };
  387. </script>
  388. <style>
  389. page {
  390. background-color: #f7f8fc;
  391. /* height: 100%; */
  392. }
  393. </style>
  394. <style lang="scss" scoped>
  395. .supplychainon-wrapper {
  396. .headers-box {
  397. position: fixed;
  398. top: 88rpx;
  399. left: 0;
  400. width: 100%;
  401. z-index: 33;
  402. }
  403. .content-wrapper {
  404. width: calc(100% - 52rpx);
  405. height: 100%;
  406. display: flex;
  407. flex-direction: column;
  408. align-items: center;
  409. margin: 340rpx 26rpx 0rpx;
  410. padding-bottom: 60rpx;
  411. }
  412. }
  413. .mt {
  414. margin-top: 0rpx;
  415. }
  416. .mrb {
  417. margin-bottom: 26rpx;
  418. }
  419. .popup-container {
  420. width: 80vw;
  421. background: #ffffff;
  422. border-radius: 16rpx;
  423. transition: all 0.3s ease;
  424. transform: scale(0.8);
  425. opacity: 0;
  426. padding: 20rpx;
  427. .popup-header {
  428. padding: 0rpx 15rpx 15rpx;
  429. border-bottom: 1px solid #eee;
  430. .title {
  431. font-size: 36rpx;
  432. font-weight: 600;
  433. color: #333;
  434. text-align: center;
  435. }
  436. }
  437. }
  438. .content-wrapper-popup {
  439. overflow: auto;
  440. .form-item {
  441. padding: 15rpx 0;
  442. .item-label {
  443. font-size: 28rpx;
  444. font-weight: 600;
  445. color: #333;
  446. margin-bottom: 12rpx;
  447. }
  448. }
  449. }
  450. .popup-show {
  451. transform: scale(1);
  452. opacity: 1;
  453. }
  454. .action-btns {
  455. display: flex;
  456. padding: 24rpx;
  457. gap: 20rpx;
  458. border-top: 1px solid #eee;
  459. .btn {
  460. flex: 1;
  461. height: 80rpx;
  462. line-height: 80rpx;
  463. border-radius: 8rpx;
  464. font-size: 28rpx;
  465. &.prev-step {
  466. background: #f8f8f8;
  467. color: #666;
  468. }
  469. &.submit-btn {
  470. background: #007aff;
  471. color: white;
  472. }
  473. }
  474. }
  475. /deep/.uni-popup {
  476. z-index: 667;
  477. }
  478. </style>