add.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <div>
  3. <el-button
  4. :size="btn_size ? btn_size : 'small'"
  5. type="primary"
  6. @click="show"
  7. >
  8. {{ title_btn ? $t(title_btn) : $t("新 建") }}
  9. </el-button>
  10. <el-drawer
  11. :title="title_drawer ? $t(title_drawer) : $t(`新建积分商品`)"
  12. :visible.sync="dialogFormVisible"
  13. direction="rtl"
  14. append-to-body
  15. :show-close="false"
  16. size="700px"
  17. @close="onCancel"
  18. >
  19. <div class="drawer__panel">
  20. <el-row :gutter="20">
  21. <el-form
  22. :model="form"
  23. :rules="rules"
  24. ref="form"
  25. :label-width="tool.onlyZh('100px')"
  26. label-position="right"
  27. size="mini"
  28. >
  29. <el-col :span="24">
  30. <el-form-item :label="$t('商品名称:')" prop="itemname">
  31. <el-input
  32. v-model="form.itemname"
  33. :placeholder="$t('请填写商品名称')"
  34. ></el-input>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="24">
  38. <el-form-item :label="$t('商品编号:')" prop="itemno">
  39. <el-input
  40. v-model="form.itemno"
  41. :placeholder="$t('请填写商品编号')"
  42. ></el-input>
  43. </el-form-item>
  44. </el-col>
  45. <el-col :span="24">
  46. <el-form-item :label="$t('积分:')" prop="points">
  47. <el-input-number
  48. v-model="form.points"
  49. :min="0"
  50. :placeholder="$t('请填写积分')"
  51. />
  52. </el-form-item>
  53. </el-col>
  54. <el-col :span="24">
  55. <el-form-item :label="$t('价格:')" prop="price">
  56. <el-input-number
  57. v-model="form.price"
  58. :min="0"
  59. :precision="2"
  60. :placeholder="$t('请填写价格')"
  61. />
  62. </el-form-item>
  63. </el-col>
  64. <el-col :span="24">
  65. <el-form-item :label="$t('辅助单位:')" prop="isauxunit">
  66. <el-checkbox
  67. v-model="form.isauxunit"
  68. :true-label="1"
  69. :false-label="0"
  70. >
  71. {{ $t("是否需要辅助单位") }}
  72. </el-checkbox>
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="24">
  76. <el-form-item :label="$t(`单位`)" prop="unitid">
  77. <el-select
  78. style="width: 100%"
  79. v-model="form.unitid"
  80. :placeholder="$t('请选择')"
  81. clearable
  82. >
  83. <el-option
  84. v-for="item in unitData"
  85. :key="item.unitid"
  86. :label="$t(item.unitname)"
  87. :value="item.unitid"
  88. >
  89. </el-option>
  90. </el-select>
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="24">
  94. <el-form-item :label="$t(`单位组`)" :prop="form.isauxunit === 1 ? 'unitgroupid' : ''">
  95. <el-select
  96. style="width: 100%"
  97. v-model="form.unitgroupid"
  98. :disabled="form.isauxunit === 0"
  99. :placeholder="$t('请选择')"
  100. clearable
  101. >
  102. <el-option
  103. v-for="item in unitGroupData"
  104. :key="item.unitgroupid"
  105. :label="$t(item.unitgroupname)"
  106. :value="item.unitgroupid"
  107. >
  108. <p style="float: left">
  109. {{ item.unitgroupname }}
  110. </p>
  111. <p
  112. style="
  113. float: right;
  114. color: #8492a6;
  115. font-size: 13px;
  116. "
  117. >
  118. {{ item.conversionrate
  119. }}{{ item.unitname }}/{{
  120. item.auxunitname
  121. }},{{ $t(`换算率`) }}:{{
  122. "1:" + item.conversionrate
  123. }}
  124. </p>
  125. </el-option>
  126. </el-select>
  127. </el-form-item>
  128. </el-col>
  129. <el-col :span="24">
  130. <el-form-item :label="$t('最小订购量:')" prop="orderminqty">
  131. <el-input-number
  132. v-model="form.orderminqty"
  133. :min="1"
  134. :placeholder="$t('请填写最小订购量')"
  135. />
  136. </el-form-item>
  137. </el-col>
  138. <el-col :span="24">
  139. <el-form-item :label="$t('订购增量:')" prop="orderaddqty">
  140. <el-input-number
  141. v-model="form.orderaddqty"
  142. :min="1"
  143. :placeholder="$t('请填写订购增量')"
  144. />
  145. </el-form-item>
  146. </el-col>
  147. <el-col :span="24">
  148. <el-form-item :label="$t('备注:')" prop="remarks">
  149. <el-input
  150. type="textarea"
  151. v-model="form.remarks"
  152. :placeholder="$t('请填写备注')"
  153. ></el-input>
  154. </el-form-item>
  155. </el-col>
  156. <el-col :span="20">
  157. <el-form-item :label="$t('商品图:')">
  158. <div
  159. class="flex-align-center"
  160. style="flex-wrap: wrap"
  161. >
  162. <uploadFile
  163. ref="upload"
  164. style="margin: 10px 10px 10px 0"
  165. :folderid="folderid"
  166. accept=".JPG,.PNG,.jpg,.png"
  167. type="image"
  168. :bindData="bindData"
  169. @onSuccess="uploadSuccess"
  170. >
  171. </uploadFile>
  172. <template v-if="title_btn == '编辑'">
  173. <previewImage
  174. style="
  175. margin: 10px 10px 10px 0;
  176. "
  177. v-for="image in form.attinfos"
  178. :key="image.index"
  179. :image="image"
  180. :deletebtn="true"
  181. @onSuccess="clearCover"
  182. ></previewImage>
  183. </template>
  184. </div>
  185. <small
  186. style="display: block; margin-top: 18px"
  187. class="info"
  188. >{{
  189. $t(`注:建议上传图片大小`)
  190. }}1024x1024px,{{ $t("大小不超过") }}2M,{{
  191. $t("格式为")
  192. }}JPG/PNG</small
  193. >
  194. </el-form-item>
  195. </el-col>
  196. </el-form>
  197. </el-row>
  198. </div>
  199. <div class="fixed__btn__panel">
  200. <el-button
  201. size="small"
  202. @click="onCancel"
  203. class="normal-btn-width"
  204. >{{ $t("取 消") }}</el-button
  205. >
  206. <el-button
  207. :loading="loading"
  208. class="normal-btn-width"
  209. size="small"
  210. :type="title_btn == '编辑' ? 'warning' : 'primary'"
  211. @click="onSubmit"
  212. >{{ title_btn == "编辑" ? $t("保 存") : $t("确 定") }}
  213. </el-button>
  214. </div>
  215. </el-drawer>
  216. </div>
  217. </template>
  218. <script>
  219. import uploadFile from "@/components/upload/preview_upload.vue";
  220. import previewImage from "@/components/previewImage/index.vue";
  221. export default {
  222. name: "add",
  223. components: { uploadFile, previewImage },
  224. props: {
  225. btn_size: String,
  226. title_btn: String,
  227. title_drawer: String,
  228. data: Object,
  229. },
  230. data() {
  231. return {
  232. folderid: JSON.parse(sessionStorage.getItem("folderid"))
  233. .appfolderid,
  234. bindData: {},
  235. unitData: [],
  236. unitGroupData: [],
  237. loading: false,
  238. dialogFormVisible: false,
  239. currentData: {},
  240. form: {
  241. sc_points_productid: 0,
  242. itemno: "",
  243. itemname: "",
  244. price: 0,
  245. points: 0,
  246. isauxunit: 0,
  247. orderminqty: 1,
  248. orderaddqty: 1,
  249. unitid: "",
  250. unitgroupid: "",
  251. remarks: "",
  252. attinfos: [],
  253. },
  254. rules: {
  255. itemname: [
  256. {
  257. required: true,
  258. message: this.$t("请填写商品名称"),
  259. trigger: "blur",
  260. },
  261. ],
  262. itemno: [
  263. {
  264. required: true,
  265. message: this.$t("请填写商品编号"),
  266. trigger: "blur",
  267. },
  268. ],
  269. points: [
  270. {
  271. required: true,
  272. message: this.$t("请填写积分"),
  273. trigger: "blur",
  274. },
  275. ],
  276. price: [
  277. {
  278. required: true,
  279. message: this.$t("请填写价格"),
  280. trigger: "blur",
  281. },
  282. ],
  283. },
  284. };
  285. },
  286. methods: {
  287. show() {
  288. this.unitlist();
  289. this.dialogFormVisible = true;
  290. if (this.title_btn == "编辑") {
  291. this.form = Object.assign({}, this.form, this.data);
  292. }
  293. },
  294. async unitlist() {
  295. const res = await this.$api.requested({
  296. id: "20220922084803",
  297. version: 1,
  298. nocache: true,
  299. content: {
  300. pageSize: 1000,
  301. where: {
  302. condition: "",
  303. },
  304. },
  305. });
  306. this.unitData = res.data;
  307. },
  308. onSubmit() {
  309. this.$refs["form"].validate(async (valid) => {
  310. if (!valid) return false;
  311. if (this.form.isauxunit === 1 && !this.form.unitgroupid) {
  312. this.$message.error(this.$t("请选择单位组"));
  313. return false;
  314. }
  315. this.loading = true;
  316. const res = await this.$api.requested({
  317. id: 2026052209110806,
  318. content: this.form,
  319. });
  320. if (res.code === 0) {
  321. this.loading = false;
  322. this.$message.error(
  323. res.msg ||
  324. (this.title_btn == "编辑" ? this.$t("编辑失败") : this.$t("新建失败"))
  325. );
  326. return;
  327. }
  328. this.loading = false;
  329. this.$message.success(
  330. this.title_btn == "编辑" ? this.$t("编辑成功") : this.$t("新建成功")
  331. );
  332. this.bindData = {
  333. ownertable: "sc_points_product",
  334. ownerid: res.data.sc_points_productid,
  335. usetype: "default",
  336. };
  337. this.$refs["upload"].toUpload();
  338. this.$emit("onSuccess");
  339. this.dialogFormVisible = false;
  340. this.$refs["form"].resetFields();
  341. setTimeout(() => {
  342. if (this.form.sc_points_productid && this.form.sc_points_productid !== 0) {
  343. this.$router.push({
  344. path: "/pointsbasedproductsDetail",
  345. query: {
  346. id: this.form.sc_points_productid,
  347. rowindex: res.data.rowindex,
  348. },
  349. });
  350. this.$store.dispatch("changeDetailDrawer", true);
  351. } else {
  352. this.$emit("onSuccess");
  353. }
  354. }, 500);
  355. });
  356. },
  357. onCancel() {
  358. this.dialogFormVisible = false;
  359. this.$refs["form"].resetFields();
  360. },
  361. uploadSuccess(res) {
  362. this.$emit("onSuccess");
  363. },
  364. clearCover() {
  365. this.queryMain();
  366. },
  367. async queryMain() {
  368. const res = await this.$api.requested({
  369. id: 2026052209105106,
  370. content: {
  371. nocache: true,
  372. sc_points_productid: this.$route.query.id,
  373. },
  374. });
  375. this.form = Object.assign({}, this.form, res.data);
  376. },
  377. },
  378. };
  379. </script>