price-edit-modal.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <view class="price-edit-modal">
  3. <!-- 遮罩层 -->
  4. <view class="mask" @tap="close"></view>
  5. <!-- 弹窗内容 -->
  6. <view class="modal-content">
  7. <view class="modal-header">修改销售价</view>
  8. <template v-for="(listItem, isd) in upList">
  9. <view class="wparnkd-centent" :key="'sdfgdxf' + isd">
  10. <!-- 商品类型选择 -->
  11. <view class="goods-type" :key="'sdfgdf' + isd">
  12. <text class="label">商品类型:</text>
  13. <radio-group @change="handleTypeChange">
  14. <view
  15. v-for="(item, index) in goodsTypesData"
  16. :key="item.value + '_index' + index"
  17. class="radio-item"
  18. >
  19. <label>
  20. <radio
  21. :value="String(item.value)"
  22. :checked="currentType === item.value"
  23. color="#007AFF"
  24. />
  25. {{ item.label }}
  26. </label>
  27. </view>
  28. </radio-group>
  29. </view>
  30. <view v-if="uplength != 1 && uplength != 0" :key="'sdfgdttf' + isd">
  31. <view style="padding-bottom: 10rpx">规格:</view>
  32. <view style="color: #007aff">{{ listItem.detail.规格 }}</view>
  33. </view>
  34. <!-- 价格输入区域 -->
  35. <view class="price-input" :key="'sdfotktmgdf' + isd">
  36. <text class="tip"
  37. >最低销售价格不能小于:{{ listItem.min_market_price }}</text
  38. >
  39. <view class="input-row">
  40. <text>销售价:</text>
  41. <input
  42. type="number"
  43. v-model="fuzupList[isd].price"
  44. placeholder="请输入销售价"
  45. @input="calculateProfit"
  46. />
  47. </view>
  48. </view>
  49. <!-- 计算结果显示 -->
  50. <view class="profit-display" :key="'sdkkf' + isd">
  51. <view>销售价:{{ listItem.price || "0.00" }}</view>
  52. <view>养老金:{{ listItem.gong_pension || "0.00" }}</view>
  53. <view>创客利润:{{ listItem.plate_mer_profit || "0.00" }}</view>
  54. </view>
  55. </view>
  56. </template>
  57. <button class="confirm-btn" @tap="handleConfirm">确定</button>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { editSupplyChainPrice } from "@/commit/product.js";
  63. export default {
  64. props: {
  65. productData: {
  66. type: Object,
  67. default: () => {},
  68. },
  69. merInfo: {
  70. type: Object,
  71. default: () => {},
  72. },
  73. },
  74. data() {
  75. return {
  76. currentPrice: "",
  77. currentType: "",
  78. goodsTypes: "", // 商品类型
  79. productStyles: [
  80. { value: "", label: "全部" },
  81. { value: "0", label: "单规格" },
  82. { value: "1", label: "多规格" },
  83. ],
  84. upList: [], //attrValue
  85. uplength: 0, //attrValue.length
  86. pnjen: "", //product_id
  87. fuzupList: [], //attrValue
  88. };
  89. },
  90. watch: {
  91. productData: {
  92. handler(val) {
  93. this.getProductData(val);
  94. },
  95. deep: true,
  96. },
  97. },
  98. mounted() {
  99. this.getProductData(this.productData);
  100. },
  101. methods: {
  102. handleTypeChange(e) {
  103. this.currentType = e.detail.value;
  104. // 这里可以添加不同类型的价格计算逻辑
  105. },
  106. calculateProfit() {
  107. // 示例计算逻辑,实际根据业务需求修改
  108. this.pensionFund = this.currentPrice * 0.05;
  109. this.makerProfit = this.currentPrice * 0.15;
  110. },
  111. getProductData(val) {
  112. const _this = this;
  113. const ev = (val && val.attrValue) || [];
  114. const en = val && val.product_id;
  115. const etype = val && val.type;
  116. _this.goodsTypes = etype;
  117. _this.upList = JSON.parse(JSON.stringify([...ev]));
  118. _this.fuzupList = JSON.parse(JSON.stringify([...ev]));
  119. _this.pnjen = en;
  120. _this.uplength = ev.length;
  121. },
  122. handleConfirm() {
  123. var reg =
  124. /(^[1-9]([0-9]+)?(.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9].[0-9]([0-9])?$)/;
  125. //单拿数据 组成新的数组
  126. const skuArr = this.fuzupList.map((project) => ({
  127. sku_id: project.gong_sku_id,
  128. edit_price: project.price,
  129. }));
  130. let _this = this;
  131. const isEmtyPrice = skuArr.some(
  132. (item) =>
  133. item.edit_price == "" ||
  134. item.edit_price == null ||
  135. item.edit_price == undefined
  136. );
  137. const isZQPrice = skuArr.some(
  138. (item) => !reg.test(item.edit_price) || item.edit_price == 0
  139. );
  140. if (isEmtyPrice) {
  141. uni.showToast({ title: "请输入金额", icon: "none" });
  142. return;
  143. }
  144. if (isZQPrice) {
  145. uni.showToast({ title: "请输入正确金额", icon: "none" });
  146. return;
  147. }
  148. editSupplyChainPrice(this.pnjen, {
  149. skuArr: skuArr,
  150. type: this.goodsTypes,
  151. }).then(
  152. (res) => {
  153. if (res.data.status == 200) {
  154. uni.showToast({ title: res.data.message, icon: "none" });
  155. _this.$emit("confirm");
  156. } else {
  157. uni.showToast({ title: res.data.message, icon: "none" });
  158. }
  159. },
  160. (fail) => {
  161. uni.showToast({ title: res.data.message, icon: "none" });
  162. }
  163. );
  164. },
  165. close() {
  166. this.$emit("close");
  167. },
  168. },
  169. computed: {
  170. goodsTypesData() {
  171. if (this.merInfo && this.merInfo.mer_id == 324) {
  172. return [
  173. { label: "普通商品", value: 1 },
  174. { label: "会员商品", value: 8 },
  175. { label: "高级会员商品", value: 10 },
  176. { label: "合伙人商品", value: 14 },
  177. { label: "股权商品", value: 15 },
  178. { label: "合伙人+股权商品", value: 16 },
  179. ];
  180. } else {
  181. return [{ label: "普通商品", value: 1 }];
  182. }
  183. },
  184. },
  185. };
  186. </script>
  187. <style scoped>
  188. /* 弹窗公共样式 */
  189. .mask {
  190. position: fixed;
  191. top: 0;
  192. left: 0;
  193. right: 0;
  194. bottom: 0;
  195. background: rgba(0, 0, 0, 0.5);
  196. z-index: 999;
  197. }
  198. .modal-content {
  199. position: fixed;
  200. top: 50%;
  201. left: 50%;
  202. transform: translate(-50%, -50%);
  203. width: 85%;
  204. max-width: 600rpx;
  205. background: #fff;
  206. border-radius: 12rpx;
  207. padding: 30rpx;
  208. z-index: 1000;
  209. }
  210. .wparnkd-centent{
  211. max-height: 70vh;
  212. overflow-y: auto;
  213. }
  214. .modal-header {
  215. font-size: 18px;
  216. font-weight: bold;
  217. margin-bottom: 20rpx;
  218. text-align: center;
  219. }
  220. /* 商品类型选择样式 */
  221. .goods-type {
  222. margin-bottom: 30rpx;
  223. }
  224. .radio-item {
  225. margin: 15rpx 0;
  226. display: flex;
  227. align-items: center;
  228. }
  229. /* 输入区域样式 */
  230. .price-input {
  231. margin: 20rpx 0;
  232. }
  233. .input-row {
  234. display: flex;
  235. align-items: center;
  236. margin: 15rpx 0;
  237. }
  238. input {
  239. border: 1rpx solid #ddd;
  240. padding: 10rpx;
  241. border-radius: 8rpx;
  242. flex: 1;
  243. margin-left: 15rpx;
  244. }
  245. /* 按钮样式 */
  246. .confirm-btn {
  247. background: #007aff;
  248. color: white;
  249. margin-top: 30rpx;
  250. border-radius: 8rpx;
  251. }
  252. .profit-display {
  253. padding: 15rpx 0;
  254. border-top: 1rpx solid #eee;
  255. margin-top: 20rpx;
  256. }
  257. </style>